找出所有不同的单词,按字典序从小到大输出。 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.
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<sstream>
using namespace std;
set<string> dict;
int main(){
string s,buf;
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); //用于数据线转换,向ss插入s,*插入的时候已经把原来的数据都清空了*
while(ss>>buf) { //sstream里重载了>>运算符,从stream抽取刚存入的值 (可以把空格去掉)
//cout<<buf<<endl;
dict.insert(buf);
}
}
for(set<string>::iterator it=dict.begin();it!=dict.end();it++)
cout<<*it<<"\n";
return 0;
}