UVA10815-5.3-Andy's First Dictionary(集合set的用法)
来源:互联网 发布:windows phone 8.1gdr2 编辑:程序博客网 时间:2024/06/10 06:42
UVA10815-5.3-Andy’s First Dictionary(集合set的用法)
题目描述:
链接:
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=835&problem=1756&mosmsg=Submission+received+with+ID+18662803
这个题的意思是给一段英文文章,找出文章中所有不相同的单词,按字典序的顺序输出出来。
题目分析:
这个题主要是学习set的用法,set也是c++里面的一个新的东西。
集合:set
set是数学上的一个集合,每个元素最多只出现一次。
而且书上说set已经定义了小于运算符,我的理解是输入的东西会自动从大到小排序。
这个题有理解一个新东西,steringstream ss,好像是用来把一些数据定义成一个流?然后向一个东西里面输入。
大概类似于这样用:
stringstream ss(s); while(ss>>buf) dict.insert(buf);
因为前面已经把s里面的非字母内容全部变成了空格,所以buf会一个单词一个单词的读入,不读空格。
这里有一个insert()函数。
我找到了一篇博文讲这个函数。
http://blog.csdn.net/hzw05103020/article/details/51785727
另外还有两行代码:
for(set<string>::iterator it = dict.begin();it != dict.end();++it) cout << *it << endl;
按书中解释,set::iterator 的意思是迭代器,是STL中的重要概念,类似于指针的用法。但我也不是很懂=。=
给出代码:
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<map>#include<set>#include<vector>#include<algorithm>#include<stack>#include<queue>#include<cctype>#include<sstream>using namespace std;set<string>dict;int main(){ string s,buf; while(cin>>s) { for(int i=0;i<s.length();i++) { if(isalpha(s[i])) s[i]=tolower(s[i]);//tolower将大写字母变为小写 else s[i]=' '; } stringstream ss(s); //ss<<s; while(ss>>buf) dict.insert(buf); } for(set<string>::iterator it = dict.begin();it != dict.end();++it) cout << *it << endl; return 0;}
0 0
- UVA10815-5.3-Andy's First Dictionary(集合set的用法)
- uva10815 Andy's First Dictionary(集合)
- UVa10815,Andy's First Dictionary, set,stringstream
- set的应用:UVa10815-Andy's First Dictionary
- UVA10815 Andy's First Dictionary(STL)
- uva10815 Andy's First Dictionary (STL)
- 例题5-3 UVa10815 Andy's First Dictionary(STL:set&&sstream的应用)
- uva10815 Andy's First Dictionary(字符串的简单处理)
- uva10815 - Andy's First Dictionary
- UVA10815 Andy's First Dictionary
- UVa10815 - Andy's First Dictionary
- UVa10815 Andy's First Dictionary
- UVA10815 Andy's First Dictionary
- UVA10815 Andy's First Dictionary
- UVA10815 - Andy's First Dictionary
- UVA10815 Andy's First Dictionary
- UVa10815 Andy's First Dictionary
- UVA10815 - Andy's First Dictionary
- C语言实验——输出字符串(sdut oj)
- activti 5.1.16 工作流引擎学习帮助手册
- VS编译clang
- 《Angular2初步涉略》
- git 学习笔记一
- UVA10815-5.3-Andy's First Dictionary(集合set的用法)
- Spring的《XML显式装配bean》- 默认自动装配
- 小博老师解析JavaWeb核心技术 ——AJAX第一弹
- GitHub上的markdown格式一些利于排版的用法
- Jenkins构建Android项目持续集成之findbugs的使用
- BootStrap:去除BootStrap所有圆角效果-----说真的看到圆角我就有点烦躁
- bzoj1043 [HAOI2008]下落的圆盘
- Effective Java(一)
- Minix 1.0文件系统的实现