Uva 10815 Andy's First Dictionary (字典序)
来源:互联网 发布:多多软件站下载 编辑:程序博客网 时间:2024/06/04 19:00
Problem B: Andy's First Dictionary
Time limit: 3 seconds
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
题目大意:
将所有的字符串转化为小写,去重,然后按照字典序输出。
#include <iostream>#include <stdio.h>#include <string>#include <string.h>#include <algorithm>#include <ctype.h>using namespace std;const int N = 1000010;string word[N];int main() {char ch;int cut = -1;int flag = 0;while( (ch = getchar()) != EOF ) {if( (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') ) {if(flag == 0) {cut++;}if( ch >= 'A' && ch <= 'Z') {ch = tolower(ch);}word[cut] += ch;flag++;}else {flag = 0;}}sort(word,word+cut+1);cout<<word[0]<<endl;for(int i = 1; i <= cut; i++) {if(word[i] != word[i-1]) {cout<<word[i]<<endl;}}return 0;}
- Uva 10815 Andy's First Dictionary (字典序)
- UVa 10815 Andy's First Dictionary 【set】【字典序】
- UVa OJ 10815-Andy's First Dictionary
- uva 10815 Andy's First Dictionary
- UVa 10815 - Andy's First Dictionary
- UVA 10815 - Andy's First Dictionary
- uva-10815 - Andy's First Dictionary
- UVa 10815 - Andy's First Dictionary
- UVA 10815 Andy's First Dictionary
- UVa 10815 - Andy's First Dictionary
- UVA 10815 Andy's First Dictionary
- UVa-10815 - Andy's First Dictionary
- UVA 10815 - Andy's First Dictionary
- uva -- 10815 Andy's First Dictionary
- UVA 10815 Andy's First Dictionary
- uva 10815 Andy's First Dictionary
- UVa 10815 - Andy's First Dictionary
- uva - 10815 - Andy's First Dictionary
- 如何增强一个类的某个方法
- MongoDB: 聚集管道
- map容器和vector的结合使用(UVA 11991)
- struts2之单个文件上传【转】
- 原材料配送问题的蚁群算法实现(C语言)
- Uva 10815 Andy's First Dictionary (字典序)
- Oracle 中 Cursor 介绍
- Android L Developer Preview
- 又见GCD
- 什么是java序列化,怎样实现java的序列化?
- W5100使用中的常见问题
- me
- 设计模式实现(二)---策略模式、策略模式与简单工厂模式结合使用
- POJ1228-Grandpa's Estate