输入一个文本,找出所有不同的单词(连续的字母序列),按字典序从小到大输出。
样例输入:
Adventure 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.
样例输出:(只保留了前5行)
a
adventures
blondes
came
Disneyland
#include<iostream> #include<sstream> #include<set> #include<string> using namespace std; int main() { set<string> dict; 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); while(ss>>buf) dict.insert(buf); } for(set<string>::iterator it=dict.begin();it!=dict.end();it++) cout<<*it<<endl; return 0; } //ctrl+z结束输入还有一部分没明白,继续努力!!!