UVA 10815 Andy's First Dictionary(字符处理)
2016-01-03 20:14
489 查看
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.
in the text does not exceed 5000.
构造一个不反复的字典。
map一下就可以。
(大写和小写)
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 wordsin 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
构造一个不反复的字典。
map一下就可以。
(大写和小写)
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map> typedef long long LL; using namespace std; #define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i ) #define REP( i , n ) for ( int i = 0 ; i < n ; ++ i ) #define CLEAR( a , x ) memset ( a , x , sizeof a ) map<string,int>p; struct node{ char s[1100]; }e[5500*200]; int cmp(node l1,node l2) { return strcmp(l1.s,l2.s)<0; } int main() { std::ios::sync_with_stdio(false); char str[100]; int l=0; while(scanf("%s",str)!=EOF) { int len=strlen(str); // cout<<"2333 "<<str<<endl; REP(i,len) { int j; if(isalpha(str[i])) { char s1[1100]; int ll=0; for(j=i;j<len;j++) { if(isalpha(str[j])) s1[ll++]=tolower(str[j]); else break; } s1[ll]='\0'; if(!p[s1]) { p[s1]=1; strcpy(e[l++].s,s1);} i=j-1; } } } sort(e,e+l,cmp); REP(i,l) cout<<e[i].s<<endl; return 0; }
相关文章推荐
- TCP与UDP简略
- 互联网保险O2O平台微服务架构设计
- 工厂三兄弟之抽象工厂模式
- 委托的Invoke 和 BeginInvoke 与Control的Invoke和BeginInvoke
- isPrime
- 使用Supervisor管理Linux进程
- 2015年大二上-数据结构-树和二叉树-2-(3)二叉树的构造
- mysql jdbc驱动源码分析(Statement的executeQuery 和executeUpdate方法)
- 对象
- Linux下使用 HTTP 代理连接 docker 中央服务器
- code vs电话连线
- CSS两列及三列自适应布局方法整理
- 物体运动--通过改变transform--键盘控制
- 学习Android从0开始之基础篇(2)-AndroidMainfest.xml文件详解
- Android动画基本使用
- Coin Test(南阳oj204)(水题)
- 批量下执行命令,上传下载文件的脚本
- 工厂三兄弟之工厂方法模式
- 小型无人机地面站导航显示系统设计
- socket及其相关(续篇)