博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVa 10815 Andy's First Dictionary
阅读量:4689 次
发布时间:2019-06-09

本文共 2778 字,大约阅读时间需要 9 分钟。

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 theroad. The sign read: "Disneyland Left."So they went home.

 

Sample Output

aadventuresblondescamedisneylandforkgoinghomeinleftreadroadsignsothetheytotwowentwerewhen

 


Joke and image taken from the Web

 

题目的意思是,给一篇文章,找出里面所有的单词,按字典序排序后输出

只要把所有的单词全都找出来,然后排序,排好之后在输出时去掉重复的即可

 

1 #include
2 #include
3 #include
4 #include
5 6 using namespace std; 7 8 string s[1000000]; 9 10 int main()11 {12 char temp[1000];13 int t=-1;14 15 while(gets(temp))16 {17 bool flag=false;18 for(int i=0;temp[i]!='\0';i++)19 {20 if(temp[i]>='a'&&temp[i]<='z')21 if(flag)22 s[t]=s[t]+temp[i];23 else24 {25 t++;26 s[t]=temp[i];27 flag=true;28 }29 else if(temp[i]>='A'&&temp[i]<='Z')30 if(flag)31 s[t]=s[t]+(char)(temp[i]+32);32 else33 {34 t++;35 s[t]=(char)(temp[i]+32);36 flag=true;37 }38 else39 flag=false;40 }41 }42 43 sort(s,s+t+1);44 45 cout<
<
[C++]

 

转载于:https://www.cnblogs.com/lzj-0218/p/3526467.html

你可能感兴趣的文章
Delphi 之 定时器 (TTimer组件)
查看>>
linux常用命令
查看>>
Treap 树堆 容易实现的平衡树
查看>>
轮播无缝
查看>>
解决CentOS内网机通过Windows下架设代理来访问网络
查看>>
弱逼发福利——BZOJ简易题解
查看>>
C语言函数指针简单应用
查看>>
简单快捷好用的vim配置和终端配置推荐
查看>>
ListView普通列表控件的使用
查看>>
struts2配置中因为包名问题遇到的No result defined for action错误
查看>>
HDU 2553(N皇后问题)
查看>>
vs快捷键大全
查看>>
基本四则运算
查看>>
C#操作SQL Server数据库
查看>>
64、剑指offer--滑动窗口最大值
查看>>
Python 闭包和装饰器
查看>>
控制流程之while循环
查看>>
Gym102028G Shortest Paths on Random Forests 生成函数、多项式Exp
查看>>
sqlserver一些对象的创建
查看>>
php的json_encode函数问题
查看>>