#include <iostream>
#include <stdio.h>
#include <string.h>

int main()
{
    char text[1000] = "i am groot we are groot";
	char *word[1000] = { NULL, }; // 단어
    int count[1000] = { 0, }; // 출현 횟수

    int totalWordCount = 0; // 단어 수
    char *w; // 읽은 단어
    int i;
    bool isRegistered;

    printf("당신이 원하는 문장을 쓰세요. " );
    // 테스트를 위해서 text를 위에서 미리 입력하고 밑에는 주석처리함
    // scanf("%s",text,sizeof(text));
    
    w = strtok(text, " "); // 단어 읽기
    while (w) {

        // 등록 여부
        isRegistered = false;
        for (i = 0; i < totalWordCount; i++)
        {
            if (strcmp(word[i], w) == 0)
            {
            	isRegistered = true;
            	count[i]++;
            	break;
            }
        }
        
        if(isRegistered)
        {
        	break;
        }
        else
        {
        	word[totalWordCount] = w; // 등록
            count[totalWordCount] = 1;
            totalWordCount++;
        }

        w = strtok(NULL, " "); // 다음 단어
    }

    for (i = 0; i < totalWordCount; i++)
    {
        printf("\n%s: %d", word[i], count[i]);
    }

    return 0;
}