Number of words time limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 28045 accepted submission (s): 6644
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
#include <iostream>#include <set>#include <string>#include <cstdio>#include <cstring>using namespace std;char str2[10000], *p;int main(){ set<string> st; char str[1000]; int count = 0; while(gets(str2)){ if(!strcmp(str2, "#")) break; p = strtok(str2, " "); while(p){ sscanf(p, "%s", str); if(!st.count(str)) st.insert(str); p = strtok(NULL, " "); } cout << st.size() << endl; st.clear(); } return 0;}