题干:

Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the number of words that he knows is, well, not quite enough. Instead of thinking up all the words himself, he has a briliant idea. From his bookshelf he would pick one of his favourite story books, from which he would copy out all the distinct words. By arranging the words in alphabetical order, he is done! Of course, it is a really time-consuming job, and this is where a computer program is helpful.

You are asked to write a program that lists all the different words in the input text. In this problem, a word is defined as a consecutive sequence of alphabets, in upper and/or lower case. Words with only one letter are also to be considered. Furthermore, your program must be CaSe InSeNsItIvE. For example, words like "Apple", "apple" or "APPLE" must be considered the same.

Input

The input file is a text with no more than 5000 lines. An input line has at most 200 characters. Input is terminated by EOF.

Output

Your output should give a list of different words that appears in the input text, one in a line. The words should all be in lower case, sorted in alphabetical order. You can be sure that he number of distinct words in the text does not exceed 5000.

Sample Input

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

Sample Output

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

题目大意:

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

解题报告:

使用STL的set自动去重+排序的优势,并且这里使用了流处理sstream,将读入的文章整合成只含有小写字母和空格的字符串。黑科技啊!注意啊这题如果用map映射字符串的话,首先你要形成字符串所以需要在每个字符串后加  ' \0 ' !

AC代码:(20ms)

#include<iostream>
#include<string>
#include<set>
#include<sstream>
using namespace std;set<string> st;
set<string>::iterator it;
int main()
{std::ios::sync_with_stdio(false);string s,buf;while(cin>>s)  {for(int i=0;i<s.length();i++){if(isalpha(s[i]))s[i]=tolower(s[i]);elses[i]=' '; //将输入的非字符转换为空格,作为单词的分界点。 } stringstream ss(s);//导入流ss中 注意格式while(ss>>buf)st.insert(buf);//从流里导出标准的string类(因为前面已经整合好了)}for(it=st.begin();it!=st.end();it++)cout<<*it<<"\n";return 0;
}

加上这行std::ios::sync_with_stdio(false);并没快多少啊

注意字符串有的时候需要自己填 ' \0 ' 有的时候会忘掉

【UVA - 10815】 Andy's First Dictionary(STL+字符处理)相关推荐

  1. UVA 10815 Andy's First Dictionary(STL: set)

    代码如下: #include <iostream> #include <sstream> #include <stdio.h> #include <set&g ...

  2. uvaoj 10815 Andy's First Dictionary set的基本使用

    uvaoj 10815 Andy's First Dictionary set的基本使用 将单词去重后按照字典序输出. 代码如下: /********************************* ...

  3. UVa 11062 Andy's Second Dictionary(刘汝佳紫书升级题)

    在介绍这道题之前,先介绍一下紫书里面和这道题很像的一道题: 紫书P112页 的例题5-3 安迪的第一个字典(Andy's First Dictionary UVa 10815) 原题链接如下: And ...

  4. 10815 - Andy's First Dictionary

    Andy's First Dictionary PS:因为该题排版较麻烦,这里给出OJ网址:UVa10815 - Andy's First Dictionary 输入一个文本,找出所有不同的单词(连续 ...

  5. 《STL》— UVa10815 Andy's First Dictionary

    UVa10815 Andy's First Dictionary 题意:输入一个文本,找出所有不同的单词(连续字母序列),按字典序从小到大输出.单词不分大小写. #include<string& ...

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

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

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

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

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

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

  9. 字符串训练 ----- UVA 10815题目Andy's First Dictionary

    解题思路: 本题主要是涉及分割获取单词  然后按字典排序输出单词 (这个只要用qsort排序下就好了) AC代码如下 #include <iostream> #include <st ...

最新文章

  1. 软件测试培训需要学习什么
  2. c10k问题及其解决方案
  3. [转载].net 访问oracle的总结
  4. ubuntu14.04使用rails连接mysql数据库
  5. 给转型做技术的同学的一些建议
  6. 小白html图片添加文字,小白爬虫入门——爬取图片和文字(超详细)
  7. why在重写equals时还必须重写hashcode方法
  8. html请求接口_通用网关接口-FastCGI介绍
  9. Bug测试报告--在线考试系统--金州勇士
  10. Commons codec jar包详解
  11. ​选择云服务器的小窍门
  12. MOSS 2007 系列学习之安装篇(一)
  13. 蔚来:首台ET7白车身合肥工厂下线
  14. hbase建索引java api_hbase创建索引
  15. python判断变量相等_Python判断两个对象相等的原理
  16. MD5算法是否可逆?
  17. python基础数据类型之字典(基础三)
  18. AUTOSAR BSW介绍
  19. 编译原理: Subset Construction 子集构造法(幂集构造)(NFA转DFA)
  20. 线性回归、逻辑回归学习笔记

热门文章

  1. [剑指offer][JAVA]面试题第[32-1]题[从上到下打印二叉树][BFS]
  2. CF 1174 D. Ehab and the Expected XOR Problem 异或技巧
  3. 百旺智能编码_【百旺】票字版开票软件操作指南已为您备好,请查阅!
  4. 电脑无法打开特定网页_监理检测网校电脑微信无法打开公路试验检测视频课程的处理方法...
  5. 602B. Approximating a Constant Range
  6. 怎么快速写python自动化脚本_自动化脚本如何编写?
  7. python查看各列数据类型_pandas中查看数据类型的几种方式
  8. php实战搭建博客,yii2项目实战-博客管理平台的搭建
  9. oracle事务数统计,Oracle 查询事务数
  10. 西门子主程序调用子程序_S7200Smart 子程序局部变量使用教程