Problem C Andy's First Dictionary(set的使用)
题目链接: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的使用)的更多相关文章
- Problem C: Andy's First Dictionary
Problem C: Andy’s First DictionaryTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 18 Solved: 5[Submit] ...
- UVa 10815 Andy's First Dictionary
感觉这道题要比之前几个字符串处理的题目难度要大了一些. 题目大意:给若干行字符串,提取出所有单词并去掉重复的,最后按字典顺序输出. 对于输入大致有两种思路,一种是逐个读入字符,遇到字母的话就放到wor ...
- UVA-10815 Andy's First Dictionary (非原创)
10815 - Andy's First Dictionary Time limit: 3.000 seconds Problem B: Andy's First DictionaryTime lim ...
- UVa10815.Andy's First Dictionary
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 【UVA - 10815】Andy's First Dictionary (set)
Andy's First Dictionary Description 不提英文了 直接上中文大意吧 XY学长刚刚立下了再不过CET就直播xx的flag,为了不真的开启直播模式,XY学长决定好好学习英 ...
- Andy's First Dictionary
Description Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy ...
- 安迪的第一个字典(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 ...
- 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 ...
- 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 ...
随机推荐
- 最近招两个兼职的活(PHP和JSP)
我这里的活,都是兼职写作的,是两本入门教程, 一本是PHP+Nginx 一本是JSP+Servlet. 都是入门教程,有署名有稿酬,有兴趣的可以联系 QQ:837652732 验证:PHP或Java ...
- openNebula 运维系列虚拟机virtual machines operations
1,virtual machine manage,VMInstance state; http://docs.opennebula.org/4.4/user/virtual_resource_mana ...
- JQuery打造下拉框联动效果
做联动效果,若是用纯JavaScript来做,往往须要辅助页面保存须要刷新的结果集,然后渲染到原页面.考虑将须要动态刷新的内容自己主动拼接到前一个下拉框之后,当前一个下拉框onchange后,同级的后 ...
- Python之lxml
作者:Shane 出处:http://bluescorpio.cnblogs.com lxml takes all the pain out of XML. Stephan Richter lxml是 ...
- CheckBox只选择一项
最近做一个问卷的页面,客户那边说要使用checkbox而且只能选择一项 就写了下面的代码 <html xmlns="http://www.w3.org/1999/xhtml" ...
- access 语句错误
一直说是语句错误,一直没有找出来是什么错误,原来access的语句需要在字段上套一个[],这是最正确的写法,关键是动软生成的是我们一贯用的,和标准还是有些差别的,害了我好久都不知道是哪里的问题
- Windows Server 2003 安装Sql Server 2005 问题处理
安装途中遇到: 问题1.无法找到产品Microsoft SQL Server Native Client的安装程序包.请使用安装包sqlncli.msi的有效副本重新安装? 答:安装SQL Serve ...
- spring mvc 的基本注解
刚开始学习spring mvc 有很多东西不是很了解 spring mvc 四个基本注解 annotation(控制层,业务层,持久层) -- @Component.@Repository @Se ...
- 批量修改文件名java
package test0715; import java.io.File; public class FileRename {public static void main(String[] arg ...
- 《JavaScript+DOM编程艺术》的摘要(五)-----添加insertAfter
在JS原生里面,没有提供insertAfter这个方法,不过我们可以利用appendChild.insertBefore.parentNode这些方法创建一个insertAfter方法,代码如下: f ...