2072:
View Code
1 #include<iostream> 2 #include<vector> 3 #include<string> 4 #include<algorithm> 5 using namespace std; 6 7 int end(string str) 8 { 9 for(int i = 0; i < str.size(); ++i) 10 if(str[i] == '#') 11 return 1; 12 return 0; 13 } 14 /* 15 int count(string str) 16 { 17 bool flag = true; 18 int n = 0; 19 for(int i = 1; i < str.size(); ++i) 20 if(flag && str[i] != ' ') 21 { 22 n++; 23 flag = false; 24 } 25 else if(str[i] == ' ') 26 flag = true; 27 return n; 28 } 29 */ 30 void get_next(string str, int& beg, int& end) 31 { 32 for(; str[beg] == ' '; ++beg); 33 for(end = beg+1; end < str.size() && str[end] != ' '; ++end); 34 } 35 36 int count(vector<string> s) 37 { 38 int n = 1; 39 if(s.size() == 0) 40 n = 0; 41 for(int i = 1; i < s.size(); ++i) 42 if(s[i] != s[i-1]) 43 n++; 44 return n; 45 } 46 47 int main() 48 { 49 string str; 50 while(getline(cin, str)) 51 { 52 if(end(str)) 53 break; 54 int beg = 0, end = 0; 55 vector<string> s; 56 while(end < str.size()) 57 { 58 get_next(str, beg, end); 59 string ss(str.begin()+beg, str.begin()+end); 60 if(beg != str.size()) 61 s.push_back(ss); 62 beg = end; 63 } 64 sort(s.begin(), s.end()); 65 cout << count(s) << endl; 66 } 67 return 0; 68 }