利用stringstream
进行分词,把输入的字符串标准化后构建stringstream
,以cin
的方法从字符串流中读出来再添加到字典中。
using namespace std;
set<string> dict;
int main() {
string s, buf;
while (cin >> s) {
for (int i = 0, len = s.length(); i < len; ++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 << endl;
return 0;
}