HDU 2072 words, hdu2072 words
Number of words
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 27999 Accepted Submission (s): 6635
Problem Descriptionlily's good friend xiaoou333 was blank recently. He thought of a meaningless thing, that is, to count the total number of different words in an article. The following task helps xiaoou333 solve this problem.
Input contains multiple groups of data, one row in each group, and each group is a small article. Each small article is composed of lower-case letters and spaces with no punctuation marks. If it encounters "#", the input ends.
Each group outputs only one integer, which is a separate line. This integer represents the total number of different words in an article.
Sample Input
you are my friend#
Sample Output
4
Idea: first store this article in array B, filter out the words and put them into array a, and then remove the same words.
Note: line breaks and spaces at the beginning can be entered.
#include<stdio.h>#include<string.h>int main(){int i,j,k,p,word,len,F,flag;char a[300][1000],b[1000];while(gets(b),*b!='#'){k=p=word=0;len=strlen(b);F=0;memset(a,'\0',sizeof(a));for(i=0;i<len;i++){if(b[i]==' '){if(b[i+1]==' ') continue;else if(b[i+1]=='\0') break;else{p=0;k++;}}else{a[k][p]=b[i];p++;F=1;}}for(i=0;i<k;i++){flag=1;for(j=i+1;j<=k;j++){if(strcmp(a[i],a[j])==0){flag=0;break;}}if(flag) word++;}printf("%d\n",F?word+1:word);}return 0;}
Hangzhou electric acm2072, count words
Count the total number of different words in an article! Use an array to store and read all the words, and then compare them. The new word can be s ++.
Why WA?
Dude, the total number of different words in an article
The total number of different words.