单词计数,杭电0j-2072

时间:2021-05-13 03:30:55

原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=2072

【Problem Description】
lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数。下面你的任务是帮助xiaoou333解决这个问题。
【Input】
有多组数据,每组一行,每组就是一篇小文章。每篇小文章都是由小写字母和空格组成,没有标点符号,遇到#时表示输入结束。
【Output】
每组只输出一个整数,其单独成行,该整数代表一篇文章里不同单词的总数。
【Sample Input】
you are my friend #
【Sample Output】
4
【AC代码】
 #include<stdio.h>
 #include<string.h>

 ][];
 ];
 int n;

 void getword(char str[])
 {
     ;
     ;
     n = ;
     ;
     ];
     int len = strlen(str);
     str[len+] = '\n';
     str[len] = ' ';
     for(; i<=len; i++)
     {
         )
         {
             if(str[i] != ' ')
             {
                 word[cnt++] = str[i];
                 flag = ;
             }
         }
         else
         {
              if(str[i] ==  ' ')
              {
                 word[cnt] = '\0';
                 strcpy(words[n++], word);
                 cnt = ;
                 flag = ;
              }
             else
                 word[cnt++] = tr[i];
         }
     }
 }

 int count()
 {
     int i, j;
     ;
     ; i<n; i++)
     {
         ;
         ; j<n; j++)
             )
                 flag=;
         if(flag)
              ntr++;
     }
     return ntr;
 }

 int main()
 {
     while(gets(str) && strcmp(str, "#"))
     {
         getword(str);
         printf("%d\n", count());
     }
     ;
 }