Zzuli OJ 1178 Word Count

Source: Internet
Author: User

Description

Count the total number of different words in a story.

Input

There are multiple sets of data, each group of rows, each group is a small article. Each small article is composed of lowercase letters and spaces, no punctuation, and when you encounter #, the input ends.

Output

Each group only outputs an integer, which represents the total number of different words in a single story.

Sample InputYou are my friend#Sample Output4

The first time I write without seeing the problem (different words) led to WA

The idea is not a problem after clarity, with a two-dimensional array to record each word in a line of sentences, after each word to add

Every word in the end is compared to the words in front of it, and nothing is count++.

#include <iostream>#include<cstdio>#include<cstring>Charword[ -][ -];Chars[1000000];intMainintargcChar**argv) {     while(Gets (s), s[0]!='#')    {        intt=0, l=0; intlen=strlen (s); intI=0;  while(i<Len) {            if(s[i]==' ')            {                 while(s[i]==' ') I++; }            Else            {                 while(s[i]!=' '&&s[i]!=' /') Word[t][l++]=s[i++];//Save a word in a two-dimensional groupword[t][l]=' /';//don't forget to add to the end of the wordt++; L=0; }        }                /*next to filter*/        intCount=0; intflag=0;  for(intj=0; j<t;j++) {flag=0;  for(intk=0; k<j;k++)            {                if(strcmp (word[k],word[j]) = =0)//If the word is found to be the same as a previous word, the number of words is not countedflag=1; }            if(flag==0) Count++; } printf ("%d\n", Count); }    return 0;}

Zzuli OJ 1178 Word Count

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.