HDU 2072 word count

word count

Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 9   Accepted Submission(s) : 5
Problem Description
Lily's good friend xiaoou333 has been very busy recently. He thought about a meaningless thing, which is to count the total number of different words in an article. Your task below is to help xiaoou333 solve this problem.
 

Input
There are multiple sets of data, each set is a row, and each set is a small article. Each small article is composed of lowercase letters and spaces, no punctuation marks, and the end of input when # is encountered.
 

Output
Each group outputs only one integer, on its own line, that represents the total number of distinct words in an article.
 

Sample Input
 
  
you are my friend #
 

Sample Output
 
  
4
 


#include <iostream>  
#include <sstream>  
#include <string>  
#include <set>  
using namespace std;  
set<string> t;  
intmain()  
{  
    string  s,row;  
    while(getline(cin,row)&& row!="#") //按行输入  
    {  
        t.clear();     
        stringstream str;  
        str<<row; //Type conversion  
        while(str>>s) //>>Each input ends with a space or '\0' and stops when a space is encountered  
        t.insert(s); //insert  
        cout<<t.size()<<endl; //return the number of different values  
    }  
    return 0;  
}  


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324744698&siteId=291194637