题目大意:
输入一个文本,找出所有不同的单词(连续的字母序列),按照字典序大小输出。单词不区分大小写。
分析:
练习set的使用。当然也可以不用set,放到集合中排个序,输出不重复的单词;
(模仿了算法竞赛入门经典的代码);
#include <iostream>
#include <set>
#include <string>
#include <sstream>
#include <cctype>
using namespace std;
set<string> dict; // string 集合;
int main()
{
string s, buf;
while(cin >> s){
for(auto &c: s){
if(isalpha(c))
c = tolower(c);
else
c = ' ';
}
stringstream ss(s);
while(ss >> buf){
dict.insert(buf);
}
}
for(auto c: dict) //c++11标准 范围for;
cout << c << endl;
return 0;
}