前言
- 用stringstream处理输入,可以轻松解决空格
- set自动排序
#include <iostream>
#include <set>
#include <string>
#include <sstream>
using namespace std;
int main() {
string s, buf;
set<string> dict;
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 (string str : dict)
cout << str << endl;
}