HDU 2702 the number of words (similar to split a string)

The Description Problem
Lily has been a very good friend xiaoou333 empty, he thought something did not make sense of things, is an article of statistics the total number of different words. Below you xiaoou333 mission is to help solve this problem.

Input
multiple sets of data, each line, each is a small article. Each small articles are lowercase letters and spaces, no punctuation, # indicates the end of input is encountered.

Output
per group output only an integer, which make the trip alone, the total number of different words in an article of the integer representative.

Sample Input
you are my friend

Sample Output
4

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cstring>
#include <cmath>
#include <sstream>
#include <set>
using namespace std;
int main()
{
    string str,str2,op;
    while(getline(cin,str)&&str!="#")
    {
        istringstream sin(str);
        set<string> word;
        string sub;
        while(sin>>sub)
            word.insert(sub);
        cout<<word.size()<<endl;
    }
    
    return 0;
    
}
Published 94 original articles · won praise 29 · views 8576

Guess you like

Origin blog.csdn.net/m0_43382549/article/details/97093483