题目链接: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. Java学习之InputStream中read()与read(byte[] b)

    Java学习之InputStream中read()与read(byte[] b) 这两个方法在抽象类InputStream中都是作为抽象方法存在的, JDK API中是这样描述两者的: read() ...

  2. 使用QueueUserWorkerItem实现的线程池封装

    此线程池所依赖的线程类,请参看<一个Windows C++的线程类实现>: http://blog.csdn.net/huyiyang2010/archive/2010/08/10/580 ...

  3. uvalive5818 uva12376 As Long as I Learn, I Live

    题意:给出一个又向图每个图有权值和编号(正方形里的是编号),从第0号节点开始每次向当前节点所连的点中权值最大的节点移动(不会存在权值相同的节点),问最后所在的节点编号和经过的节点的权值之和. 解:模拟 ...

  4. ubuntu15.04下编译 libvirt

    很久没有编译 libvirt了. 工作需要,重新编译. [org_ref]: http://libvirt.org/compiling.html 很简单. 编译过程, 还是很多问题. 依赖包(给懒人参 ...

  5. svn 问题汇总

    1.当删除了原来的仓库时,再次新建,更新版本时会出现这个问题:

  6. VBA 开发学习--基础语法2

    VBA中的运算符 算数运算符及其作用 + 求两个数的和 -  求两个数的差:求一个数的相反数 *  求两个数的积 /   求两个数的商(保留小数位   5/2=2.5) \   整除 (保留整数位  ...

  7. 关于Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY

    google 给的android的例子里,有用到google APIs,新版本的ADT默认只有Android的SDK,如果运行平台与目标平台不一致会报:Installation error: INST ...

  8. 开发移动端web的一些知识

    由于智能机的普及,越来越多网页支持移动端了,那么如何解决适配移动端呢 在这总结一下自己的学习笔记 viewport:虚拟的容器,仅在移动设备有效 <meta name="viewpor ...

  9. C# XML与Json之间相互转换

    XML转换为Json字符串  在代码中预定义的一个xml字符串,如下: string xml = @"<?xml version=""1.0"" ...

  10. leetcode Roman to Integer python

    class Solution(object): def romanToInt(self, s): """ :type s: str :rtype: int "& ...