UVa-10815 安迪的第一个词典

字符函数库中常用的函数

函数名称 返回值
isalnum() 如果参数是字母数字,即字母或数字,该函数返回true
isalpha() 如果参数是字母,该函数返回真
isblank() 如果参数是空格或水平制表符,该函数返回true
iscntrl() 如果参数是控制字符,该函数返回true
isdigit() 如果参数是数字(0~9),该函数返回true
isgraph() 如果参数是除空格之外的打印字符,该函数返回true
islower() 如果参数是小写字母,该函数返回true
isprint() 如果参数是打印字符(包括空格),该函数返回true
ispunct() 如果参数是标点符号,该函数返回true
isspace()
如果参数是标准空白字符,如空格、进纸、换行符、回车

、水平制表符或者垂直制表符,该函数返回true

isupper() 如果参数是大写字母,该函数返回true
isxdigit() 如果参数是十六进制的数字,即0~9、a~f、A~F,该函数返回true
tolower() 如果参数是大写字符,则返回其小写,否则返回该参数
toupper() 如果参数是小写字母,则返回其大写,否则返回该参数

题目

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 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.学会运用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)

 1 #include<iostream>
 2 #include<string>
 3 #include<set>
 4 #include<sstream>
 5 using namespace std;
 6 set<string>a;
 7 int main()
 8 {
 9     string s,buf;
10     while(cin>>s)
11     {
12         for(int i=0;i<s.length();i++)
13         {
14             if(isalpha(s[i]))s[i]=tolower(s[i]);else s[i]=‘ ‘;
15         }
16             stringstream ss(s);
17             while(ss>>buf) a.insert(buf);
18
19     }
20     for(set<string>::iterator it=a.begin();it!=a.end();++it)//迭代器
21         cout<<*it<<"\n";
22     return 0;
23 }
时间: 2024-08-05 11:09:43

UVa-10815 安迪的第一个词典的相关文章

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 namespac

安迪的第一个字典 Andy&#39;s First Dictionary, UVa 10815

(Time limit: 3 seconds) Andy, 8, has a dream - he wants to produce hisvery own dictionary. This is not an easy task forhim, as the number of words that he knows is,well, not quite enough. Instead of thinking up allthe words himself, he has a briliant

UVa - 10815 Andy&#39;s First Dictionary(STL)

题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18649 #include <iostream> #include <string> #include <set> #include <sstream> using namespace std; /******************************************************************

Andy&#39;s First Dictionary UVA 10815

#include <stdio.h> #include <ctype.h> #include <string.h> #define MAXN 5000+5 #define MAXM 200+5 typedef struct Dic{ char str[MAXN]; struct Dic* next; }Dic; Dic *head; char word[MAXM]; int cnt=0; int get_word(); void convert_word(); void

UVA - 10815 Andy&#39;s First Dictionary

1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 #include <set> 5 using namespace std; 6 7 set<string> out; 8 9 int main() 10 { 11 string s,temp; 12 while(cin>>s) 13 { 14 int len(s.size()); 15 for(int

UVA 10815 Andy&#39;s First Dictionary(字符处理)

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 book

【UVa 10815】Andy&#39;s First Dictionary

真的只用set和string就行了. 如果使用PASCAL的同学可能就要写个treap什么的了,还要用ansistring. #include<cstdio> #include<cstring> #include<iostream> #include<string> #include<set> using namespace std; string s; string now; set<string> dict; bool is_al

F - Andy&#39;s First Dictionary (UVA - 10815)

- 题目大意 给出一段文章,然后将其中不重复的单词拿出来(全为小写并且由a-z的顺序). - 解题思路 我在网上看到的一个stringstream函数,它除了进行字符串和数字转换之外的另一个用途:分割单词.将字符串中所有非单词字符全部转换为空格,然后再用代码中的方法分割出单词.有这种方法就好做多了.结合set容器即可. - 代码 #include<iostream> #include<set> #include<string> #include<sstream&g

安迪的第一个字典 (Andy&#39;s First Dictionary,UVa10815)

题目描述: #include<iostream> #include<string> #include<set> #include<sstream> using namespace std; set<string> dic; string s, buf; int main() { while(cin >> s) { for(int i = 0; i < s.length(); i++) if(isalpha(s[i])) s[i]