uva 10815
来源:互联网 发布:淘宝破损补寄 编辑:程序博客网 时间:2024/06/06 19:51
Andy'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 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 <stdio.h>#include <string.h>#include <ctype.h>#include <stdlib.h>char b[100000][210];int i = 0, count = 0, j = 0;int cmp(const void *_a, const void *_b){ char* a= (char*)_a; char* b= (char*)_b; return strcmp(a,b);}int main(){ char ch; while((ch=getchar()) != EOF) { if(isalpha(ch)) { b[count][j++] = tolower(ch); } else if(isalpha(b[count][0])) { b[count++][j] = '\0'; j = 0; } } qsort(b,count,sizeof(b[0]),cmp); for(j = 0; j < count; j++) { if(strcmp(b[j],b[j+1])) //去重 printf("%s\n", b[j]); } return 0;}
用到了快排 冒泡的话会超时 思路就是把所有的单词收集到二维数组中 然后利用快排完成排序。
- uva-10815
- uva 10815
- uva 10815
- uva 10815
- uva 10815
- uva-10815
- UVA 10815
- UVa 10815
- UVA 10815
- uva 10815
- uva 10815
- UVA - 10815
- uva 10815
- UVA 10815
- UVa 10815
- UVA - 10815
- UVA-10815
- UVA 10815
- Ubuntu/CentOS下如何将普通用户提升到root权限
- Qt自动生成moc文件
- JavaScript弹出框
- Java中List和ArrayList的区别
- spring framework源码下载并导入eclipse
- uva 10815
- width和height不包括内边距、边框或外边距
- Java 2, JDK 1.4
- NYOJ 277题 车牌号
- Eclipse开发auto之dao层自动gen生成
- 【HDOJ】1164 -> Eddy's research I
- Javassist学习总结
- 通过NSTask用Cocoa执行perl脚本
- ORA-01652无法扩展temp表空间段