首页 > 其他 > 详细

UVA 10815 -- Andy's First Dictionary

时间:2018-02-07 18:30:47      阅读:202      评论:0      收藏:0      [点我收藏+]

 

技术分享图片

技术分享图片

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

原文:https://www.cnblogs.com/yxh-amysear/p/8427341.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!