HDU 2072 words, hdu2072 words

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.