安迪的第一个字典(UVa10815)

 

  题目具体描述见:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1756

 

C++11代码如下:

 1 #include<iostream>
 2 #include<set>
 3 #include<string>
 4 #include<sstream>
 5 using namespace std;
 6 set<string> dict;
 7 
 8 int main() {
 9     string s,buf;
10     while (cin >> s) {
11         for (int i = 0; i < s.length();i++) {
12             if (isalpha(s[i])) s[i]=tolower(s[i]);
13             else s[i] = ' ';
14         }
15         stringstream ss(s);
16         while(ss >> buf) dict.insert(buf);
17     }
18     for (set<string>::iterator it = dict.begin(); it != dict.end(); it++) 
19         cout << *it << endl;
20     return 0;
21 }
posted on 2018-07-05 19:09  Pink.Pig  阅读(495)  评论(1编辑  收藏  举报