Vjudge题目链接,紫书上说是为了练set这个容器用的,书上处理输入那一块值得学习。
#include<cstdio>
#include<iostream>
#include<sstream>
#include<set>
#include<string>
#include<algorithm>
using namespace std;
int main(){
string s, word;
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 >> word)dict.insert(word);
}
for(set<string>::iterator it = dict.begin(); it!=dict.end(); it++)
cout<<*it<<endl;
return 0;
}