输入一个文本,找出所有不同的单词(连续的字母序列),按字典序从小到大输出,单词不区分大小写。

输入样例

Adventures in Disneyland
Two blondes were going to Disneyland when they came to a fork in the
road. The sign read: "Disneyland Left."
So they went home.

输出样例

a
adventures
blondes
came
disneyland
fork
going
home
in
left
read
road
sign
so
the
they
to
two
went
were
when

代码

#include<iostream>
#include<algorithm>
#include<sstream>
#include<string>
#include<set>//因为可能有重复的单词,而set可以去重,使用起来更好。using namespace std;
string str,str2;
stringstream ss;
set<string> jh;
int main() {while (cin >> str ) {for (int i = 0; i < str.length(); i++) {//去除非单词字符if (isalpha(str[i])) {str[i] = tolower(str[i]);}else {str[i] = ' ';}}ss << str; //每次得清空ss//stringstream ss(str);  如果这样写就不用每次清空ss了.while (ss >> str) jh.insert(str);ss.clear();//这里必须清空...具体原因为止.}for (set<string>::iterator it = jh.begin(); it != jh.end(); it++) {cout << *it << endl;}return 0;
}

UVA10815 安迪的第一个字典 Andy‘s First Dictionary相关推荐

  1. [STL] UVA 10815 安迪的第一个字典 Andy's First Dictionary

    1.set 集合 哦....对了,set有自动按照字典序排序功能..... 声明和插入操作 #include <cstdio> #include <vector> #inclu ...

  2. 算法竞赛入门经典(第二版) | 例题5-3 安迪的第一个字典 (紫书牛啤!)(UVa10815,Andy's First Dictionary)

    概述: 输入一个文本,找出所有不同的单词,按字典序排序,去重后,输出,单词不分大小写. 储备知识: 1.sstring头文件的用法→sstring头文件函数详解 2.cctype头文件的用法→ccty ...

  3. 安迪的第一个字典(Andy‘s First Dictionary,UVa10815)

    输入一个文本,找出所有不同的单词(连续的字母序列),按字典序从小到大输出,单词不区分大小写. 要点: 利用stringstream的特点 将分离出的单词插入set<string>,set会 ...

  4. 例题5-3 安迪的第一个字典(Andy's First Dictionary,Uva 10815)

    #include<bits/stdc++.h> using namespace std; set<string> dict; int main(){string s,buf;w ...

  5. 例题5-3 安迪的第一个字典 UVa10815

    输入一段文字,将其中的所有单词按照字典序输出,要求单词均以小写形式输出,不出现重复单词. #include<bits/stdc++.h> using namespace std; int ...

  6. 例5-3 安迪的第一个字典(Andy‘s First Dictionary,UVa 10815)

    注意使用stringstream得到各个单词 #include <iostream> #include <string> #include <set> #inclu ...

  7. 例题5-3安迪的第一个字典 UVa10815--C++STL库映射set的应用

    前言 不定期更新C++的STL库以及算法练习的笔记 分享给大家 也是督促自己不断努力学习算法与程序设计 学习算法之前,要想高效简洁的写好代码,还需要熟练掌握STL库的一些方法和数据结构 参考书籍: & ...

  8. (STL,set)安迪的第一个字典

    问题: 输入一个文本,找出所有不同的单词(连续的字母序列),按字典序从小到大输出.单词不区分大小写. 样例输入 Adventures in Disneyland Two blondes were go ...

  9. 安迪的第一个字典(c++)

    嘻嘻 练习stringstream用法 #include<iostream> #include<string> #include<set> #include< ...

最新文章

  1. 【Android 逆向】Android 权限 ( adb 降权相关的属性 | ro.secure 属性 | ro.debuggable 属性 | service.adb.root 属性 )
  2. 【IT资讯】财联社:华为有望获Armv9架构CPU授权
  3. Azure VNet介绍
  4. cacheinterceptor第二次访问没被调用_访问者设计模式在OSG中的应用
  5. MongoDB(4)--MongoDB服务的启动
  6. [Mechine Learning Algorithm] 集成学习方法——Bagging和 Boosting
  7. 从helloworld回顾程序的编译过程之三——静态链接
  8. Servlet之前端web数据与后台Java数据进行交互
  9. NLP情感分析笔记(三):Faster 情感分析
  10. 文件系统挂载、卸载及相关的工具 ⑨
  11. 禅道安装与常见问题!!
  12. Java Web基础入门第三十九讲 利用易宝第三方支付实现简单在线支付
  13. 微弱信号检测_移动电话/手机信号增强器/扩大器
  14. [国家集训队]Tree I
  15. Vue_路由_query参数_params参数_命名路由_props配置_编程式路由导航_缓存路由组件_新的生命周期钩子_全局、独享、组件内路由守卫_路由的两种工作模式
  16. C++语言课程设计——超市商品管理系统
  17. vue 中 数字0和空字符串,=== 和== 用法和区别
  18. 计算机启用无线网络,有无线网络,电脑也开启了无线网络了,但是就是搜索不到无线网,怎么设置?...
  19. 列出与'SCOTT'从事相同工作的所有员工及部门名称、部门人数、平均工资
  20. 解决Ubuntu18.04下VMware开启虚拟网络编辑器无反应

热门文章

  1. 六千档最强万金油?华硕无畏Pro15 2022锐龙版笔记本体验
  2. Ratel-Kubernetes Dashboard 一键式 Kubernetes多集群资源管理平台 k8s 管理平台
  3. ICCV 2021 | 性能炸裂的通道剪枝算法ResRep(Keras复现)
  4. WiFi,你真的还安全吗?
  5. 写代码写文章勿有功利心
  6. 【Nginx】记录 nginx 配置文件中 location下根据 ua (user-agent) 判断移动端和电脑端不同浏览器来源
  7. echarts 省市区联动地图
  8. Spring Festival
  9. java 获取est时间_javascript-使用Java脚本将时区从EST转换为IST
  10. win10开机慢怎么解决_win10开机速度变慢的解决方法教程