集合set练习:Andy's First Dictionary(UVa 10815)代码

来源:互联网 发布:小米路由器域名重定向 编辑:程序博客网 时间:2024/06/06 10:53

《算法竞赛入门经典(第2版》例题5-3

#include <iostream>#include <string>#include <set>#include <sstream>using namespace std;set<string> dict; // string集合 int main(){string s, buf;while(cin >> s){for(int i = 0; i < s.length(); i++)if(isalpha(s[i])) s[i] = tolower(s[i]); else s[i] = ' '; stringstream ss(s);while(ss >> buf) dict.insert(buf);} for(set<string>::iterator it = dict.begin(); it != dict.end(); ++it)cout << *it << "\n";return 0;}


0 0
原创粉丝点击