题目链接:
题目大意:
输入一个文本,找出所有不同的单词(连续的字母序列),按字典序从小到大输出,单词不区分大小写。
Sample Input
Adventures in Disneyland Two blondes were going to Disneyland when they came to a fork in the road. The sign read: "Disneyland Left." So they went home.
Sample Output
a
adventures
blondes
came
disneyland
……
#include#include #include #include using namespace std;set dict;string s, buf;int main() { 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 ::iterator it = dict.begin(); it != dict.end(); ++it) //set具有给集合内元素去重和自动排序的功能 cout << *it << "\n"; return 0;}
2018-04-05