标签:
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1756
题意:很简单,把输入的文本,排序按字典序输出,相当于制作字典。
主要是set和stringstream的运用。
对于stringstream有个简单的程序。
#include<iostream> #include<sstream> using namespace std; int main() { string s = "12 3 4 5 6"; cout<<s<<endl; int a = 1; stringstream os; os << s; //以空格和回车键为分隔符 while(os >> a) cout<<a<<endl;//输出12\n3\n4\n5\n6\n return 0; }
#include<cstdio> #include<iostream> #include<set> #include<sstream> using namespace std; set<string> dict; 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); //分割s,插入set,按从小到大排列 } //迭代器,认识较浅,记住格式 for(set<string>::iterator it = dict.begin();it != dict.end(); ++it) cout<<*it<<"\n"; return 0; }
标签:
原文地址:http://www.cnblogs.com/Since-natural-ran/p/5763310.html