记录不同单词数目

#include #include int main()

{

char c,str[1000][1000],

flag = 0,count; int x,y,i,j;

while(1) { x = 0; y = 0;

while((c = getchar() )!= ' ')

{

if (c == '#')

{

flag = 1; break;

}

if (c != ' '&&c!='')

{ str[x][y++] = c; }

else { str[x][y] = '';

y = 0; x++;

}

}

if(flag)

{ break; }

count = 0;

for (i = 0;i <= x;i++)

{

if(str[i][0])

{

count++;

for(j = i + 1;j <= x;j++)

{

if(strcmp(str[i],str[j]) == 0)

{

str[j][0] = '';

}

}

}

}

printf("%d ",count);

}

return 0;

}

lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数。下面你的任务是帮助xiaoou333解决这个问题。
 
Input
有多组数据,每组一行,每组就是一篇小文章。每篇小文章都是由小写字母和空格组成,没有标点符号,遇到#时表示输入结束。
 
Output
每组只输出一个整数,其单独成行,该整数代表一篇文章里不同单词的总数。
 
Sample Input
you are my friend #
 
Sample Output
4
 
原文地址:https://www.cnblogs.com/luzhongshan/p/3880260.html