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; }
相关文章推荐
- HDU 2072 单词数
- HDU 2072.单词数【STL的优势以及字符串流的使用】【8月4】
- HDU 2072 单词数(set+string水过)
- HDU 2072 单词数 map的应用
- HDU 2072 单词数
- HDU 2072(单词数)题解
- hdu 2072 单词数
- hdu 2072 单词数(C++的stringstream对象)
- HDU_2072单词数
- HDU 2072 单词数 (水题我不会,错题集)
- hdu2072——单词数(STL,set)
- hdu 2072 单词数(Trie树)
- hdu_2072_统计单词数_set_检测字符串
- hdu 2072 单词数(字典树)
- HDU 2072 单词数
- HDU 2072 单词数【STL】
- hdu 2072 单词数 字典树
- hdu 2072 单词数
- hdu 2072 找不同的单词数(map&set)
- HDU 2072 单词数