题目链接:Problem C

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

思路:将字母序列都存为小写,非字母的字符变成空格,然后利用stringstream实现sting对象的自动格式化。

note: 
stringstream对象的使用
#include<sstream>
#include<iostream>
using namespace std;
int main()
{
string line,word;
while(getline(cin,line))
{
stringstream stream(line);
cout<<stream.str()<<endl;
while(stream>>word){cout<<word<<endl;}
}
return ;
}
/*
* input: shanghai no1 school 1989
* output: shanghi no1 school 1989
* shanghai
* no1
* school
* 1989
*/

code:

 #include <iostream>
#include <string>
#include <set>
#include <sstream>
#include <cctype>
using namespace std;
set<string> dirt;
int main()
{
string str, word;
dirt.clear();
while (cin >> str)
{
int len = str.size();
for (int i = ; i < len; ++i)
{
if (isalpha(str[i])) str[i] = tolower(str[i]);
else str[i] = ' ';
}
stringstream buf(str);
while (buf >> word) dirt.insert(word);
}
set<string>::iterator it;
for (it = dirt.begin(); it != dirt.end(); ++it)
cout << *it << endl;
return ;
}

Problem C Andy's First Dictionary(set的使用)的更多相关文章

  1. Problem C: Andy's First Dictionary

    Problem C: Andy’s First DictionaryTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 18 Solved: 5[Submit] ...

  2. UVa 10815 Andy's First Dictionary

    感觉这道题要比之前几个字符串处理的题目难度要大了一些. 题目大意:给若干行字符串,提取出所有单词并去掉重复的,最后按字典顺序输出. 对于输入大致有两种思路,一种是逐个读入字符,遇到字母的话就放到wor ...

  3. UVA-10815 Andy's First Dictionary (非原创)

    10815 - Andy's First Dictionary Time limit: 3.000 seconds Problem B: Andy's First DictionaryTime lim ...

  4. UVa10815.Andy's First Dictionary

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  5. 【UVA - 10815】Andy's First Dictionary (set)

    Andy's First Dictionary Description 不提英文了 直接上中文大意吧 XY学长刚刚立下了再不过CET就直播xx的flag,为了不真的开启直播模式,XY学长决定好好学习英 ...

  6. Andy's First Dictionary

    Description Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy ...

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

    Description Andy, , has a dream - he wants to produce his very own dictionary. This is not an easy t ...

  8. STL语法——集合:set 安迪的第一个字典(Andy's First Dictionary,UVa 10815)

    Description Andy, , has a dream - he wants to produce his very own dictionary. This is not an easy t ...

  9. UVA - 10815 - Andy's First Dictionary STL

    Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him ...

随机推荐

  1. centos 6.7 perl 版本 This is perl 5, version 22 安装DBI DBD

    <pre name="code" class="cpp">centos 6.7 perl 版本 This is perl 5, version 22 ...

  2. nautilus-open-terminal右键随处打开终端

    Nautilus-Open-Terminal : 可随处打开终端的 Nautilus 插件 nautilus-open-terminal-0.17-4.el6.x86_64 是一个让你随处都可以打开终 ...

  3. centos ldap

    Standalone LDAP Daemon, slapd(standalone lightweight access protocol)Lightweight Directory Access Pr ...

  4. openStack use

    <1,project security> security groyps Security groups--> are sets of IP filter rules() that ...

  5. 【转】Ubuntu Linux 下文件名乱码(无效的编码)的快速解决办法

    原博文地址:http://www.cnblogs.com/york-hust/archive/2012/07/07/2580388.html 文件是在WIndows 下创建的,Windows 的文件名 ...

  6. Class constructor

     // example: class constructor #include <iostream> using namespace std; class Rectangle { in ...

  7. [转]spring 监听器 IntrospectorCleanupListener简介

    "在服务器运行过程中,Spring不停的运行的计划任务和OpenSessionInViewFilter,使得Tomcat反复加载对象而产生框架并用时可能产生的内存泄漏,则使用Introspe ...

  8. mlpack:可伸缩C++机器学习库(转)

    摘要:mlpack是一个可伸缩C++机器学习库,它的目的是让新用户通过简单.一致的API使用机器学习,同时为专业用户提供C++的高性能和最大灵活性. mlpack是一个直观.快速.可伸缩的C++机器学 ...

  9. xhprof failed to execute cmd: " dot -Tpng". stderr: `sh: dot: command not found '

    wget http://www.graphviz.org/pub/graphviz/ARCHIVE/graphviz-2.28.0.tar.gz tar xzvf graphviz-2.28.0.ta ...

  10. C++学习之函数指针

     C++学习之函数指针          和数据项类似,函数也有地址,函数的地址是存储在机器语言代码的内存的开始地址.通常,这些地址对用户而言,不重要也没什么用处,但对程序而言,它却很有用. 一.函数 ...