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 ...
随机推荐
- jQuery改变兄弟元素样式,及:not([class="allclassname"])筛选小结
以前一直对于jquery感到很畏惧,最近做点击图表变色,将其他元素图片复位的小需求,总结了一下一点小心得. 主要两点是:1.将所有兄弟元素的样式设置为一样,对于子元素的遍历: 2.对于特殊不需要变化的 ...
- js模板引擎
js模板引擎包括如下: template 官方参考:http://aui.github.io/artTemplate BaiduTemplate 官方参考:http://baidufe.github. ...
- 爬虫:获取多次跳转后的页面url
<?php $url = "xxxx"; $xx = get_headers($url,true); var_dump($xx); ?> Nbimer主页 剖面加阴影应 ...
- python 学习中遇到的问题
一.安装pip中遇到的问题. 出现错误:ImportError:DLL load failed :%1不是有效的win32应用程序 出现问题解答: 主要是由于安装的python版本和所下载的安装包版本 ...
- android产品业务逻辑对app稳定影响太大
产品经理们, 看看你们的交互文档, 有n个逻辑分支, 在我们的实现中至少存在2*n个逻辑分支 这样极度造成了app的不稳定性,表现就是 非必须的bug很多.还有就是维护性极差 当然你们会说,你们可以写 ...
- 读javascript高级程序设计05-面向对象之创建对象
1.工厂模式 工厂模式是一种常用的创建对象的模式,可以使用以下函数封装创建对象的细节: function CreatePerson(name,age){ var p=new Object(); p.n ...
- [转]JAVA虚拟机的生命周期
JAVA虚拟机体系结构 JAVA虚拟机的生命周期 一个运行时的Java虚拟机实例的天职是:负责运行一个java程序.当启动一个Java程序时,一个虚拟机实例也就诞生了.当该程序关闭退出,这个虚拟机实例 ...
- Wifite v2 is now available
Wifite v2 is now available What's new in this version: support for cracking WPS-encrypted networks ( ...
- Solr安装入门、查询详解
Solr安装入门:http://www.importnew.com/12607.html 查询详解:http://www.360doc.com/content/14/0306/18/203871_35 ...
- 黑马程序员——OC语言 核心语法(2)
Java培训.Android培训.iOS培训..Net培训.期待与您交流! (以下内容是对黑马苹果入学视频的个人知识点总结) (一)id 1)简介:万能指针,能指向任何OC对象,相当于NSObject ...