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

uva 10815,andy's first ditionary(set,stringstream的简单运用)

时间:2019-02-06 13:10:15      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:lan   char   alpha   cout   and   begin   first   uva   []   

题意:输入一个文本,找出所有不同的单词,按字典序从小到大输出。单词不区分大小写。

样例输入:

Adventures in DisneylandTwo blondes were going to Disneyland when they came to a fork in theroad. The sign read: "Disneyland Left."So they went home.

 

样例输出:

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

代码如下:

#include<set>
#include<iostream>
#include<sstream>
#include<string>
#include<cstring>
using namespace std;
 int main(int argc, char const *argv[]) {
  string s,temp;
  set<string>dict;
  set<string>::iterator it;
  stringstream ss;
  while(cin>>s){
    for(int i=0;i<s.length();i++){
      if (isalpha(s[i])) {
        s[i]=tolower(s[i]);//字母变为小写
      }
      else s[i]= ;//将所有标点符号变为空格
      
      
    }stringstream ss(s);
      while(ss>>temp){
        dict.insert(temp);//将转换后的单词输入set
      }
  }
  for(it=dict.begin();it!=dict.end();it++){
    std::cout << *it << \n;//按字典序输出
  }
  return 0;
}

 



uva 10815,andy's first ditionary(set,stringstream的简单运用)

标签:lan   char   alpha   cout   and   begin   first   uva   []   

原文地址:https://www.cnblogs.com/azheng9929/p/10353607.html

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