http://acm.hdu.edu.cn/showproblem.php?pid=2072
The number of words this problem feel with C write very troublesome, write in C + + is relatively simple. Not much to say, direct sticker code.
#include <iostream>#include<string>#include<vector>#include<sstream>using namespacestd;intmain () {vector<string>s; strings0,s1; intFlag; while(Getline (CIN,S0)) {if(s0=="#") Break; Else{s.clear (); Istringstream sin (s0); while(sin>>S1) {Flag=0; for(intI=0; I<s.size (); i++) { if(s[i]==S1) {Flag=1; Break; } } if(flag==0) S.push_back (S1); } cout<<s.size () <<Endl; } } return 0;}
Feel the use of set is simpler, this is the online code:
#include <iostream>#include<Set>#include<string>#include<sstream>//don't forget it. using namespacestd; intMain () {stringArt; while(Getline (cin,art) && Art! ="#") {Istringstream stream (art); stringWord; Set<string>map; while(Stream >>word) {Map.insert (word); } cout<<map.size () <<Endl; } return 0; }
HDU 2072 Word Count