Number of words
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 34960 Accepted Submission (s): 8380
Problem descriptionlily's good friend xiaoou333 recently very empty, he thought of a meaningless thing, is to count the number of different words in an article. Your task below is to help xiaoou333 solve the problem.
Input has multiple sets of data, each set of rows, each of which 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 an article.
Sample Input
You are my friend#
Sample Output
4
Authorlily
SOURCE Zhejiang University of Technology Network tryouts
Recommendlinle
Analysis: Water problem do not spray ... Simple application of Set ~ ~ ~
AC Code:
#include <bits/stdc++.h>using namespace Std;const int maxn = 10005;set<string> P;int main () { #ifdef sxk< C1/>freopen ("In.txt", "R", stdin); #endif//Sxk string T, S; while (Getline (CIN, s) && s! = "#") { int n = s.size (); P.clear (); for (int i=0; i<n; i++) { t = ""; while (S[i] >= ' A ' && s[i] <= ' z ') T + = s[i++]; if (t! = "") P.insert (t); } printf ("%d\n", P.size ()); } return 0;}
HDU 2072 Word count (STL map)