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 ...
随机推荐
- poj1651 最优矩阵乘法动态规划解题
题目描述: 有若干个矩阵{Ai},元素都为整数且已知矩阵大小. 如果要计算所有矩阵的乘积A1 * A2 * A3 .. Am,最少要多少次整数乘法? 输入 第一行一个整数n(n <= 100), ...
- python entry points 例子
pbr的介绍不多,http://ju.outofmemory.cn/entry/156745 $ mkdir entry_test; cd entry_test; git init $ mkdir ...
- centos6.5vpn搭建
centos6.5vpn搭建整个搭建流程,服务端,客户端安装及测试. 达到的效果: 在安装vpn客户端的机器可通过vpn(virtual private network)专用线路(vpn主配置文件中定 ...
- Let the Balloon Rise(map)
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- .net 文件下载
/** 输入参数* _Request: Page.Request 对象* _Response: Page.Response 对象* _fileName: 下载文件名* _fullPath: 带文件名下 ...
- 谷歌识图、google识图如何知道图片相似?
转自:http://www.hahait.com/news/185.html 原理非常简单易懂.我们可以用一个快速算法,就达到基本的效果.这里的关键技术叫做“感知哈希算法”(Perceptual ha ...
- Activity之onWindowFocusChanged
public void onWindowFocusChanged (boolean hasFocus) 参数hasFocus: the window of this activity has focu ...
- JS脚本验证大全
/** * 2009-10-01 * 贺 臣 * 情 缘 * js各种表单数据验证 *//***************************************************** ...
- Scala io操作
1. 读文件 scala特有的是scala.io.Source,例如: import scala.io._ Source.fromFile(“cn.scala”,”utf8”).mkString 逐行 ...
- (C++编程规范第17条)避免使用”魔数“
1.摘要: 程序设计并非魔数,所以不要故弄玄虚:要避免在代码中使用诸如42和3.14159这样的文字常量.它们本身没有提供任何说明,并且因为增加了难于检测的重复而使维护更加复杂.可以用符号名称和表达式 ...