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

时间: 2024-08-03 05:59:31

Andy's First Dictionary的相关文章

UVA - 10815 Andy&#39;s First Dictionary

1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 #include <set> 5 using namespace std; 6 7 set<string> out; 8 9 int main() 10 { 11 string s,temp; 12 while(cin>>s) 13 { 14 int len(s.size()); 15 for(int

Winter-2-STL-E Andy&#39;s First Dictionary 解题报告及测试数据

use stringstream Time Limit:3000MS     Memory Limit:0KB 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 thin

UVa - 10815 Andy&#39;s First Dictionary(STL)

题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18649 #include <iostream> #include <string> #include <set> #include <sstream> using namespace std; /******************************************************************

UVA 10815 Andy&#39;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 book

10815 - Andy&#39;s First Dictionary解答

采用数组链表的方式,来插入读入的单词,逐个字符读入单词. #include <stdio.h> #define LEN 200 #include <string> #include <string.h> #include <stdlib.h> struct node { char word[LEN]; struct node * next; }; typedef struct node Word; int main(){ Word* Dict[30]; fo

UVa10815 Andy&#39;s First Dictionary (STL)

链接:http://acm.hust.edu.cn/vjudge/problem/18649分析:set容器应用.set中每个元素最多只出现一次.自定义类型也可以构造set,必须定义“小于”运算符.set中的元素从小到大已排好序. 1 #include <iostream> 2 #include <string> 3 #include <cctype> 4 #include <set> 5 #include <sstream> 6 using n

小白书训练-Andy&#39;s First Dictionary

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1756 题意:给你一段文字,把所有的单词挑出来,然后排序打印. 首先是挑出来,用指针加数组轻轻松解决问题,然后排序,因为用数组不能快拍,便用了string,先转换为string然后一个快拍. 打印的时候不能打印重复的,因此,在打印的时候一个判断就好. 因为数组大小问题RE到死啊啊啊啊

安迪的第一个字典 Andy&#39;s First Dictionary, UVa 10815

(Time limit: 3 seconds) Andy, 8, has a dream - he wants to produce hisvery own dictionary. This is not an easy task forhim, as the number of words that he knows is,well, not quite enough. Instead of thinking up allthe words himself, he has a briliant

【UVa 10815】Andy&#39;s First Dictionary

真的只用set和string就行了. 如果使用PASCAL的同学可能就要写个treap什么的了,还要用ansistring. #include<cstdio> #include<cstring> #include<iostream> #include<string> #include<set> using namespace std; string s; string now; set<string> dict; bool is_al