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 ...
随机推荐
- IOSJSBRIGE商品内容模板
<p> 内容 </p> <script> window.onerror = function(err) { log('window.onerror: ' + err ...
- 在Centos 5.x或6.x上安装RHEL EPEL Repo
本文介绍了如何在CentOS 5.x或者CentOS 6.x的系统上使用Fedora Epel repos一个第三方repo:remi资源库.这些资源包并不是天然地支持CentOS,但是提供了很多流行 ...
- Android 天天爱消除辅助
简介 <天天爱消除>是一款移植于手游的消除类益智游戏,该游戏只有通过手机登录QQ跟微信才能进行,这样一来这款游戏必然会大红大紫. 功能 开发Android自动化触屏事件,录制操作脚本,实现 ...
- mciSendString用法
使用MCI API,源文件中需要包含头文件 Mmsystem.h,在Project->Settings->Link->Object/libray module中加入库 Winmm.l ...
- cors技术
简称跨域资源共享: 若是配置nodejs: 需在公共路由添加三句话:代码如下: // 全局头设置 app.all('*', function(req, res, next) { res.set({ ' ...
- hibernate环境配置和使用
一.hibernate简单介绍 Hibernate是一个开放源码的对象关系映射框架,它对JDBC进行了很轻量级的对象封装,使得Java程序猿能够随心所欲的使用对象编程思维 ...
- Android tp的虚拟按键(virtual key)处理
Android tp的虚拟按键处理 现在在越来越多的Android的手机都是虚拟按键来操作,但是对于开发者来说可能会关心Android对虚拟按键如何处理的.对Linux熟悉的人可能会说,it's ea ...
- 227. Basic Calculator
1. 问题描述 Implement a basic calculator to evaluate a simple expression string. The expression string c ...
- rem单位
rem单位 rem基础 px是固定单位,不同分辨率下效果不一样,导致网页布局出现偏差. em是根据父元素来改变字大小 rem是根据根元素html来改变字体大小,只要改变了根元素的font-size就可 ...
- KVC中setValuesForKeysWithDictionary:
本文转载于:http://my.oschina.net/u/2407613/blog/524879?p={{page}} 从字典映射到一个对象,这是KVC中的一个方法所提供的,这个方法就是 setVa ...