您的位置:首页 > 其它

HDU_2072 单词数

2014-07-26 16:11 239 查看

单词数

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

you are my friend
#

 
[align=left]Sample Output[/align]

4

 
#include<stdio.h>
#include<string.h>
int n;
char str[10005],ch[1005][1005];
void sort(  )
{
int i = 0;
while( str[i] )
{
if( str[i] == ' ' )
{
++i;    //往下一个字符走
continue;
}
int j = 0;
while( str[i] && str[i] != ' ' )  //把单词存入二位字符型数组,以备后面比较
ch
[j++] =str[i++];
ch
[j] = 0;
int f = 1;
for( int j = 0; j < n; ++j )
{    if( !strcmp( ch[j],ch
) )
{
f = 0;
break;
}
}
if( f )
++n;
}
}
int main( )
{
while( gets( str ) )
{
n = 0;
if( str[0] == '#' )
break;
else sort(  );
printf( "%d\n",n );
}
return 0;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: