1. 程式人生 > >UVA 10815 -- Andy's First Dictionary

UVA 10815 -- Andy's First Dictionary

gpo esp std sign sig left set post 圖片

技術分享圖片

技術分享圖片

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

  通過這道題,學習了一下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 }

UVA 10815 -- Andy's First Dictionary