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

Posted azheng9929

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了uva 10815,andy's first ditionary(set,stringstream的简单运用)相关的知识,希望对你有一定的参考价值。

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

样例输入:

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 << 
;//按字典序输出
  }
  return 0;
}

 

























以上是关于uva 10815,andy's first ditionary(set,stringstream的简单运用)的主要内容,如果未能解决你的问题,请参考以下文章

Uva 10815.Andy's First Dictionary

UVA - 10815 Andy's First Dictionary

安迪的第一个字典 Andy's First Dictionary, UVa 10815

UVa10815 Andy's First Dictionary (STL)

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

UVA - 10815Andy's First Dictionary (set)