题目链接: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. Spring AOP AspectJ Pointcut 表达式例子

    主要来源:http://howtodoinjava.com/spring/spring-aop/writing-spring-aop-aspectj-pointcut-expressions-with ...

  2. ubuntu中如何关闭防火墙?

    只需要输入 root@stgman-desktop:~#  sudo ufw disable 防火墙在系统启动时自动禁用

  3. cmd命令 拷贝某文件夹及其子文件夹文件到其它文件夹

    @ECHO OFF cd/d %H:\FileLoc\CNET&cd.. ::echo 拷贝"%H:\FileLoc\CNET"中文件到"H:\FileLocTe ...

  4. 初识Maven

    今天开始学习怎样使用maven,听起来挺神奇的东西,我们来一步一步的加以剖析. Maven的一些具体的论文的东西,网上很多博客介绍,这里我就不逐一介绍,下面我们从安装maven开始讲解: (1)Mav ...

  5. css滤镜(转载)

    STYLE="filter:filtername(fparameter1, fparameter2...)" (Filtername为滤镜的名称,fparameter1.fpara ...

  6. 【android】两个按钮的宽度各占屏幕的一半

    <LinearLayout> <Button android:layout_height="wrap_content" android:layout_width= ...

  7. U盘安装CentOS6.x报错:Missing ISO 9660 Image

    以前都是DVD安装CentOS,这次因为装固态硬盘,然后把光驱给卸载了.所以就尝试用U盘引导安装CentOS,结果安装时竟然出现了Missing ISO 9660 Image的错误. 解决方案: 将C ...

  8. C++/C#结构体转化-二维数组-bytes To Strings

    C++结构体 typedef struct VidyoClientRequestGetWindowsAndDesktops_ { /*! The number of application windo ...

  9. events模块

    /** * Created by Administrator on 2016/8/3. */ var http = require("http"); //Node 导入文件系统模块 ...

  10. USACO Section 4.2 The Perfect Stall(二分图匹配)

    二分图的最大匹配.我是用最大流求解.加个源点s和汇点t:s和每只cow.每个stall和t 连一条容量为1有向边,每只cow和stall(that the cow is willing to prod ...