Problem C: Andy's First Dictionary
Problem C: Andy’s First Dictionary
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 18 Solved: 5
[Submit][Status][Web Board]
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
my answer:
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
#include<stdio.h>
#include<cstring>
#include<string>
using namespace std;
char * dtox(char a[])//函数。。。由大写转化成小写 ;
{
int t1=strlen(a);
for (int i=;i!=t1;i++)
if(a[i]>='A'&&a[i]<='Z')
a[i]=a[i]+;
return a;
}
char * quza(char b[])//函数。。。去掉符号部分;
{
int t2=strlen(b);
char s[];
int f=;
dtox(b);
for(int j=;j!=t2;j++){
if(b[j]>='a'&&b[j]<='z')
s[f++]=b[j];
}
s[f]='\0';
return s;
}
int main()
{ char a[][],word[][];
int i=,k=;
while(gets(a[i]))
{
int t=strlen (a[i]);
if(t==)
continue;
char *p;
p=strtok(a[i]," ");
while(p)
{
strcpy(word[k++],quza(p));
p=strtok(NULL," ");
} i++;
}
//sort (word[0],word[0]+k);
for(int t=;t!=k;t++){
int w=t;
for(int m=t;m!=k;m++)
if(strcmp(word[w],word[m])>)w=m;
char r[];
strcpy(r,word[w]);
strcpy(word[w],word[t]);
strcpy(word[t],r);
}
for (int h=;h!=k;h++){
if(strcmp(word[h],word[h+]))
cout <<word[h]<<endl;
}
return ;
}
Problem C: Andy's First Dictionary的更多相关文章
- Problem C Andy's First Dictionary(set的使用)
题目链接:Problem C 题意:输入一个文本,找出所有不同的单词,按照字典序从小到大输出,单词不区分大小写. 思路:将字母序列都存为小写,非字母的字符变成空格,然后利用stringstream实现 ...
- UVa 10815 Andy's First Dictionary
感觉这道题要比之前几个字符串处理的题目难度要大了一些. 题目大意:给若干行字符串,提取出所有单词并去掉重复的,最后按字典顺序输出. 对于输入大致有两种思路,一种是逐个读入字符,遇到字母的话就放到wor ...
- UVA-10815 Andy's First Dictionary (非原创)
10815 - Andy's First Dictionary Time limit: 3.000 seconds Problem B: Andy's First DictionaryTime lim ...
- 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 (set)
Andy's First Dictionary Description 不提英文了 直接上中文大意吧 XY学长刚刚立下了再不过CET就直播xx的flag,为了不真的开启直播模式,XY学长决定好好学习英 ...
- Andy's First Dictionary
Description Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy ...
- 安迪的第一个字典(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 ...
- STL语法——集合:set 安迪的第一个字典(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 ...
- UVA - 10815 - Andy's First Dictionary STL
Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him ...
随机推荐
- 解决ArcSDE图层名被占用的问题
点击文章查看 当你发现上面那篇文章时你已经接近成功了,但还差最后一步! <!- -delete from sde.GDB_OBJECTCLASSES where NAME = upper(' ...
- Matrix(多线程dp)
Matrix Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- asp.net 使用my97 datepicker实现前后两个日期的范围界定
说明:日期选择后,前面的日期小于等后面的日期,后面的日期大于等于前面的日期.点点看就知道了:) - 这里将周末日期不可选.代码如下: <html xmlns="http://www.w ...
- 使用sqlplus批量执行脚本的总结
当然,我们可以在plsql中执行,但是在实际生产环境中,可能更多的是使用简便的sqlplus.步骤如下: 1.登陆client sqlplus connect <username>/< ...
- English - little,a little,a few,few的区别
few.a few.little.a little的区别和联系: few / a few(形容词)用来修饰可数名词,few表示否定意义,没有,几乎没有, a few表示有肯定意思,有几个. 例如:a ...
- xmanager 使用
linux 上安装xterm windows上启动命令: /usr/bin/xterm -ls -display $DISPLAY
- 浅谈Spring(一)
一.Spring引言 Spring是一款轻量级框架,代码入侵量很小,并且还是众多优秀的设计模式的组合(工厂.代理.模板.策略). 特点: 1.方便解耦,简化开发 通过Spring提供的IoC容器,我们 ...
- Cglib学习站点(转)
1.CGlib简单介绍,访问地址:http://www.blogjava.net/stone2083/archive/2008/03/16 /186615.html,从简单的示例到不同业务场景的变化, ...
- MySQL varchar和char类型
varchar和char是两种最主要的字符串类型.不幸的是,很难精确地解释这些值是怎么储存在磁盘和内存中的,因为这根存储引擎的具体实现有关.下面的描述假设使用的存储引擎是InnoDB或者MyISAM. ...
- 一次U盘安装Ubuntu双系统实录
准备:Win7系统(原来就在我电脑的系统) UltraISO(把系统写进U盘的工具) EasyBCD(双系统引导修复工具) 笔记本电脑(我的是联想Y470N) U盘一个 步骤: U盘准备工作: 插入U ...