UVA 10815 -- Andy's First Dictionary

 

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.

sample output

a
adventures
blondes
came
disneyland
fork
going
home
in
left
read
road
sign
so
the
they
to
two
went
were
when

c++ STL -- set和multiset

  通过这道题,学习了一下set和stringstream。

 1 #include<iostream>
 2 #include<string>
 3 #include<set>
 4 #include<sstream>
 5 using namespace std;
 6 
 7 set<string> dict;//string集合
 8 
 9 int main()
10 {
11     string s,buf;
12     while(cin>>s)
13     {
14         for(int i = 0;i<s.length();i++)
15         {//将不是字母的都处理为' '
16             if(isalpha(s[i])) s[i] = tolower(s[i]);else s[i] = ' ';
17         }
18         stringstream ss(s);
19         while(ss >> buf) dict.insert(buf);
20     }
21     for(set<string>::iterator it = dict.begin();it != dict.end();it++)
22         cout<<*it<<endl;
23     return 0;
24 }

 

posted @ 2018-02-07 16:38  卉卉卉大爷  阅读(107)  评论(0编辑  收藏  举报