【问题描述】输入一个文本,找出所有不同的单词(连续的字母序列),按字典序从小到大输出。单词不区分大小写。
【样例输入】
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.
【样例输出】
aadventures
blondes
came
disneyland
fork
going
home
in
left
read
road
sign
so
the
they
to
two
went
were
when
#include<iostream>
#include<string>
#include<set>
#include<sstream>
using namespace std;
set<string> dict; //为字典设置一个名为dict-short的集合,它基于字符串类型;
int main(){
string s,buf;
while (cin>>s){
for (int i=0;i<s.length();i++)
if (isalpha(s[i])) //isalpha函数:判断字符ch是否为英文字母,若为英文字母,返回非0.若不是字母,返回0
s[i]=tolower(s[i]); //如果它是一个字母,把它变成小写。
else
s[i]=' ';
stringstream ss(s); //如果是空格,忽略它
while (ss>>buf)
dict.insert(buf); //插入到已经是有序的集合,TYkon说这是一个平衡的树里面 (不懂)
}
for (set<string>::iterator it=dict.begin();it!=dict.end();++it)//迭代器就像一个点,从头到尾扫描它并输出 (不懂)
cout<<*it<<endl; //NOTICE按点输出
return 0;
}