UVa 10815 安迪的第一个字典
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1756
题意:很简单,把输入的文本,排序按字典序输出,相当于制作字典。
主要是set和stringstream的运用。
对于stringstream有个简单的程序。
#include<iostream>
#include<sstream>
using namespace std; int main()
{
string s = "12 3 4 5 6";
cout<<s<<endl;
int a = ;
stringstream os;
os << s; //以空格和回车键为分隔符
while(os >> a)
cout<<a<<endl;//输出12\n3\n4\n5\n6\n
return ;
}
#include<cstdio>
#include<iostream>
#include<set>
#include<sstream>
using namespace std; set<string> dict; int main()
{
string s,buf;
while(cin>>s){
for(int i = ;i < s.length(); i++)
if(isalpha(s[i])) s[i] = tolower(s[i]);
else s[i] = ' ';
stringstream ss(s);
while(ss >> buf) dict.insert(buf); //分割s,插入set,按从小到大排列
}
//迭代器,认识较浅,记住格式
for(set<string>::iterator it = dict.begin();it != dict.end(); ++it)
cout<<*it<<"\n";
return ;
}
UVa 10815 安迪的第一个字典的更多相关文章
- [STL] UVA 10815 安迪的第一个字典 Andy's First Dictionary
1.set 集合 哦....对了,set有自动按照字典序排序功能..... 声明和插入操作 #include <cstdio> #include <vector> #inclu ...
- 安迪的第一个字典(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 ...
- 安迪的第一个字典(Andy's First Dictionary,Uva 10815)
输入一个文本,找出所有不同的单词(连续的字母序列),按字典序从小到大输出.单 词不区分大小写. 样例输入: Adventures in Disneyland Two blondes were goin ...
- set的运用 例题5-3 安迪的第一个字典(Andy's First Dictionary,Uva 10815)
#include<bits/stdc++.h>using namespace std;set<string> dict;int main(){ string s, buf; w ...
- stl的集合set——安迪的第一个字典(摘)
set就是数学上的集合——每个元素最多只出现一次,和sort一样,自定义类型也可以构造set,但同样必须定义“小于”运算符 以下代码测试set中无重复元素 #include<iostream&g ...
- 安迪的第一个字典(UVa10815)
题目具体描述见:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_prob ...
- 5_3 安迪的第一个字典(UVa10815)<set的使用>
Andy 是个 8 岁的孩子,他梦想要制作一本他自己的字典. 这并不是一件容易的事,因为他认识的字还不是那么多. 他并不想要自己去想这本字典中该放哪些字,他有个聪明的主意. 就是拿出他最喜欢的一本故事 ...
- 安迪的第一个字典 (Andy's First Dictionary,UVa10815)
题目描述: #include<iostream> #include<string> #include<set> #include<sstream> us ...
随机推荐
- <开心一笑> 前端工程师你们伤不起!
前端工程师你们伤不起!! 来自: 刻铭 2011-03-11 14:09:53 前端工程师伤不起 老子几年前进了互联网圈!!!!!!!成了前端工程师,名字是不是很拉风,有木有!!!!!!!! 尼玛 ...
- sqlloader导出数据和导入数据
分类: Oracle 忙了一天终于把sqlloader导出数据和导入数据弄清楚了,累死俺了... 这个总结主要分为三个大部分,第一部分(实例,主要分两步),第二部分(参数小总结),第三部分(完全参数总 ...
- 【hdu4366】dfs序线段树
#include <bits/stdc++.h> #define ll long long #define lson l, m, rt<<1 #define rson m+1, ...
- js string to int
一.js中string转int有两种方式 Number() 和 parseInt() <script> var str='1250' ; alert( Number(str) ...
- (十)Linux 网络编程之ioctl函数
1.介绍 Linux网络程序与内核交互的方法是通过ioctl来实现的,ioctl与网络协议栈进行交互,可得到网络接口的信息,网卡设备的映射属性和配置网络接口.并且还能够查看,修改,删除ARP高速缓存的 ...
- Request获取URL地址相应方法
以项目为BBS为例,以下代码置于modify.jsp: 1.request.getLocalName(): akiradunn 2.request.getServerName(): localhost ...
- mallo函数
malloc的全称是memory allocation,中文叫动态内存分配,当无法知道内存具体位置的时候,想要绑定真正的内存空间,就需要用到动态的分配内存.原型为extern void *malloc ...
- 读javascript高级程序设计09-BOM
一.window 1.在全局作用域中定义的变量和函数会被归在window对象. var a=1,b=2; function add(a,b){ return a+b; } console.log(wi ...
- to my friends-Don't give up so fast
早上听到大学挺要好的朋友突然说要换行,心情就一股莫名的哀伤,因为当初是三个人一起约定好的,要朝着我们共同的目标而努力奋斗的,这股热情怎能这么轻易地被现实的冷水浇灭.没错,我们是刚出社会的毛头小子,我们 ...
- C#/ASP.NET MVC微信公众号接口开发之从零开发(三)回复消息 (附源码)
C#/ASP.NET MVC微信接口开发文章目录: 1.C#/ASP.NET MVC微信公众号接口开发之从零开发(一) 接入微信公众平台 2.C#/ASP.NET MVC微信公众号接口开发之从零开发( ...