码迷,mamicode.com
首页 > 其他好文 > 详细

UVA 10815 -- Andy's First Dictionary

时间:2018-02-07 19:32:18      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:fork   ace   dict   分享   将不   col   while   alpha   name   

 

技术分享图片

技术分享图片

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

标签:fork   ace   dict   分享   将不   col   while   alpha   name   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!