Description

Andy, , 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  lines. An input line has at most  characters. Input is terminated by EOF.

Output

Your output should give a list of different words that appears .

Sample Input

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.

Sample Output

a
adventures
blondes
came
disneyland
fork
going
home
in
left
read
road
sign
so
the
they
to
two
went
were
when
1.中文翻译

大体的中文意思就是:输入一个文本,找出所有不同的单词(连续的字母序列),按字典序列从小到大输出。单词不区分大小写,输入输出和上面一样。

2.分析

这个题比较简单,我学习的是《算法竞赛入门经典》这本书的代码。

1.学会运用set容器;(有个小知识点,set容器,元素只能出现一次,并且插入可以从小到大排序)

2.学习字符函数库中常用的函数

3.学会stringstream(可参考这篇博文:http://blog.csdn.net/xw20084898/article/details/21939811)

4.最后运行记得是  在空行  ctrl+z +回车。(至于为什么,参考博文:http://blog.csdn.net/kevin_ut/article/details/8576740)

3.说明

set是一个集合 和康托前辈的一样 集合中的元素不重复 且集合中的元素是有序的(自动有序化) TY菌介绍说其内部实质是一个平衡树

set不是数组 只能通过迭代器(iterator)把里面的元素倒出来 迭代器相当于是指针 扫描的是地址 因此输出的时候需要用*variation

4.声明

需要用到头文件set

set<string> dict; 建立一个集合 其名为dict 基类型是string

5.常用函数

dict.begin() dict.end()返回集合最初和最后的元素的地址

这是写这个例题用到的

6.代码
 #include<iostream>
 #include<string>
 #include<set>
 #include<sstream>
 using namespace std;  

 set<string> dict;//set up a set called dict-short for dictionary,and it's based on string type;  

 int main(){
     string s,buf;
     while (cin>>s){
         ;i<s.length();i++)
           if (isalpha(s[i])) s[i]=tolower(s[i]);//if it's an letter,turn it lowercase.Others turn space and use stringstream to leave it out=ignore it
           else s[i]=' ';
         stringstream ss(s);
         while (ss>>buf) dict.insert(buf);//insert it into the set which is already in order,TYkon said it's a balanced tree inside
     }
     for (set<string>::iterator it=dict.begin();it!=dict.end();++it)//iterator just like a point,scan it from beginning to end and output
       cout<<*it<<endl;//NOTICE output by point
     ;
 }

还是英文注释不过看懂应该问题不大

isalpha()判断是否是字母 如果是就用头tolower()转换成小写 否则就转为空格 这样是为了字符串流重读入的时候能够把空格去掉

特别强调一下本例中出现的迭代器

 for (set<string>::iterator it=dict.begin();it!=dict.end();++it)//iterator just like a point,scan it from beginning to end and output
       cout<<*it<<endl;//NOTICE output by point

迭代器iterator相当于是个类型 it是一个变量 基类型是iterator 它从开始扫到结尾的前一个【据TY菌解释 像数组一样 最后一位是没有值的 数组是一个结束标志 不知集合最后是什么】输出的时候 由于it扫描的是地址 要输出*it

这个好像用到了stl set的语法....

显然对于set我还知之甚少 还需要在今后的学习中不断掌握

今天晚上此时已是0:15,写完博客,明天上课.....

 

本文部分引用http://blog.csdn.net/ametake

安迪的第一个字典(Andy's First Dictionary,UVa 10815)的更多相关文章

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

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

  2. 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 ...

  3. Andy‘s First Dictionary UVA - 10815

      Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for h ...

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

    题目描述: #include<iostream> #include<string> #include<set> #include<sstream> us ...

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

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

  6. 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 ...

  7. 5_3 安迪的第一个字典(UVa10815)<set的使用>

    Andy 是个 8 岁的孩子,他梦想要制作一本他自己的字典. 这并不是一件容易的事,因为他认识的字还不是那么多. 他并不想要自己去想这本字典中该放哪些字,他有个聪明的主意. 就是拿出他最喜欢的一本故事 ...

  8. UVa 10815 安迪的第一个字典

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. stl的集合set——安迪的第一个字典(摘)

    set就是数学上的集合——每个元素最多只出现一次,和sort一样,自定义类型也可以构造set,但同样必须定义“小于”运算符 以下代码测试set中无重复元素 #include<iostream&g ...

随机推荐

  1. 利用jackson-databind,复杂对象对象和json数据互转

    如果简单对象,那么转换的方式比较多,这里指的复杂对象,是指对象里面存在cycle引用,比如: /** * @author ding * */@Entity@Table(name = "ser ...

  2. 【DevExpresss】3、LookUpEdit详解(转载)

    [DevExpresss]3.LookUpEdit详解 哈,今天又用到了LookUpEdit控件,主要是用来实现模糊查询和自由输入功能,然而由于长时间没用了,一阵手忙脚乱的,这里把网上收集的一部分教程 ...

  3. [bug] Cannot proceed because system tables used by Event Scheduler were found damaged at server start

    本地:mac 10.12.3  mysql 5.6 远程:linux 7.3    mysql 5.7.18.  (远程数据库yum安装,又5.6升级到5.7) 步骤:从本地数据库导出数据到远程数据库 ...

  4. Angular2.js——数据显示

    显示数据,即属性绑定机制把数据显示到用户界面上. 在Angular中最典型的数据显示方式,就是把HTML模板中的控件绑定到Angular组件的属性. 接下来介绍几种数据显示的语法和代码片段. 使用插值 ...

  5. Windows系统操作指令汇总

    CMD命令:开始->运行->键入cmd或command(在命令行里可以看到系统版本.文件系统版本) 1. appwiz.cpl:程序和功能 2. calc:启动计算器 3. certmgr ...

  6. Python:字符串的分片与索引、字符串的方法

    这是关于Python的第3篇文章,主要介绍下字符串的分片与索引.字符串的方法. 字符串的分片与索引: 字符串可以用过string[X]来分片与索引.分片,简言之,就是从字符串总拿出一部分,储存在另一个 ...

  7. 【算法系列学习】[kuangbin带你飞]专题十二 基础DP1 B - Ignatius and the Princess IV

    http://www.cnblogs.com/joeylee97/p/6616039.html 引入一个cnt,输入元素与上一个元素相同,cnt增加,否则cnt减少,当cnt为零时记录输入元素,因为所 ...

  8. Docker 打包 部署

    Docker 打包 部署 一贯的开场白,大家好: 开始学习Spring Boot ,同时也再学习 Maven 自动化构建.  项目的部署环境是 Linux 服务器,Docker容器. 之所以写这篇博客 ...

  9. OC 动态类型和静态类型

    多态 允许不同的类定义相同的方法 动态类型 程序直到执行时才能确定所属的类 静态类型 将一个变量定义为特定类的对象时,使用的是静态形态 将一个变量定义为特定类的对象时,使用的是静态类型,在编译的时候就 ...

  10. Docker - 容器直连

    本文是在原文基础上的实际操作验证记录和细节补充. 默认情况下,容器连接到虚拟网桥docker0提供的虚拟子网中,容器之间通过默认网关(虚拟网桥docker0接口地址)建立连接. 如果不使用虚拟网桥,用 ...