水题(细节考察getline) 之 hdu 2072
// [7/23/2014 Sjm]
/*
细节考察:
WA了几次。。。由于空格可以被 getline 读入,所以增加判断条件。。。
测试用例:
ab (注意ab前有一个空格)
输出:
1
*/
1 #include <iostream> 2 #include <cstdlib> 3 #include <cstdio> 4 #include <string> 5 #include <set> 6 using namespace std; 7 8 bool Judge(char ch) { 9 if (ch >= 'a' && ch <= 'z') { 10 return true; 11 } 12 return false; 13 } 14 15 int main() 16 { 17 //freopen("input.txt", "r", stdin); 18 string str; 19 while (getline(cin, str) && str != "#") { 20 str += "."; 21 string t_str; 22 set<string> myset; 23 for (int i = 0; i < str.size(); ++i) { 24 if (Judge(str[i])) { 25 t_str += str[i]; 26 }else { 27 if (t_str.size()) { // 此处增加判断条件 28 myset.insert(t_str); 29 } 30 t_str = ""; 31 } 32 } 33 cout << myset.size() << endl; 34 myset.clear(); 35 } 36 return 0; 37 }