Andy's First Dictionary
Description
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
HINT
#include<stdio.h>
#include<string.h>
char a[5000];
int t;
void zhuanhuan() //大写和小写转换
{
int i;
for(i=0;i<t;i++)
{
if(a[i]>='A'&&a[i]<='Z')
a[i]=a[i]+32;
}
}
int main()
{
char b[5000][200];
int i,j,m,n;
m=0;
int flag;
while(gets(a))//scanf("%s",a)!=EOF
{
j=0;
n=0;
t=strlen(a);
if(t==0)
continue;
zhuanhuan();
for(i=0;i<t;i++)
{
if((a[i]<='z'&& a[i]>='a'))
b[m][n++]=a[i];
else if(a[i]==' ')
{
b[m][n++]='\0';
m++;
n=0;
}
}
b[m++][n]='\0';
}
for(i=m-1;i>=0;i--)
{
for(j=0;j<i;j++)
{
if(strcmp(b[j],b[j+1])>0)
{
char w[30];
strcpy(w, b[j]);
strcpy(b[j],b[j+1]);
strcpy(b[j+1],w);
}
}
}
for(i=0;i<m;i++)
{
flag=1;
for(j=0;j<i;j++)
{
if((strcmp(b[i],b[j]))==0)
{
flag=0;
break;
} }
if(flag==1)
printf("%s\n",b[i]);
}
//for(i=0;i<m;i++)
// printf("%s\n",b[i]);
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
Andy's First Dictionary的更多相关文章
- UVA 10815 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 ...
- Uva 10815-Andy's First Dictionary(串)
Problem B: Andy's First Dictionary Time limit: 3 seconds Andy, 8, has a dream - he wants to produce ...
- Swift语法3.03(类型Types)
类型 在Swift中,有两种类型:命名型类型和复合型类型.命名型类型是在定义时可以给定的特定名字的类型.命名型类型包括类,结构体,枚举和协议.例如,自定义的类MyClass的实例拥有类型MyClass ...
- UVa10815.Andy's First Dictionary
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA-10815 Andy's First Dictionary (非原创)
10815 - Andy's First Dictionary Time limit: 3.000 seconds Problem B: Andy's First DictionaryTime lim ...
- UVa 10815 Andy's First Dictionary
感觉这道题要比之前几个字符串处理的题目难度要大了一些. 题目大意:给若干行字符串,提取出所有单词并去掉重复的,最后按字典顺序输出. 对于输入大致有两种思路,一种是逐个读入字符,遇到字母的话就放到wor ...
- Andy's First Dictionary
Description Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy ...
- Problem C: Andy's First Dictionary
Problem C: Andy’s First DictionaryTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 18 Solved: 5[Submit] ...
- 安迪的第一个字典(Andy's First Dictionary,UVa 10815)
Description Andy, , has a dream - he wants to produce his very own dictionary. This is not an easy t ...
随机推荐
- cocos2d-x游戏开发系列教程-坦克大战游戏之敌方坦克AI的编写
在上篇我们完成了子弹和地图碰撞的检测,在这篇我们将完成敌方坦克AI的编写. 具体思路是屏幕中保持有四个敌方坦克,然后坦克随机方向运动,并且子弹消失后1秒发射一次 1.我们新建一个敌方坦克的AI类来控制 ...
- css sprites 图片精灵自动生成 插件
grunt-spritesmith https://www.npmjs.com/package/grunt-spritesmith
- Struts2 学习笔记17 I18N国际化
讲解一下国际化的内容,比如书有些大的网站可以一键切换语言,例如中英切换,这时候就会用到国际化.但是由于struts2大多数是用来写后台,国际化并不是十分重要,而且用国际化开发会减慢开发的速度,大家只要 ...
- android 高效显示Bitmap - 开发文档翻译
由于本人英文能力实在有限,不足之初敬请谅解 本博客只要没有注明“转”,那么均为原创,转贴请注明本博客链接链接 Displaying Bitmaps Efficiently 高效显示Bitmap Lea ...
- Linux下安装配置词典GoldenDict
GoldenDict apt-get install goldendict 安装完成以后,需要自己手动加入字典,增加在线翻译网址(例如,有道,金山等),点击 编辑--dictionaries 完 ...
- js注册检测 用户名、密码、手机号、邮箱
请输入电话号码:<input name="" type="text" id="telphone" value="" ...
- 【BOI2007】【BZOJ1176】Mokia
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MB Submit: 1059 Solved: 432 [Submit][St ...
- Linq To sql入门练习 Lambda表达式基础
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 【linux】内核make编译链接相关变量定义
欢迎转载,转载时请保留作者信息,谢谢. 邮箱:tangzhongp@163.com 博客园地址:http://www.cnblogs.com/embedded-tzp Csdn博客地址:http:// ...
- 重操JS旧业第十弹:闭包
闭包是js最难理解,也是最蛋疼的一个名词,仿佛只可意会不可言传一样,有人说闭包说白了就是函数嵌套,也有人说闭包就是函数能够访问函数外部的变量,而内部的外部访问不了: 貌似都非常有道理,其实仔细想来只不 ...