UVA-10815 Andy's First Dictionary

来源:互联网 发布:手机可以禁止安装软件 编辑:程序博客网 时间:2024/06/10 05:00

UVA-10815 Andy’s First Dictionary

题目大意:输入几段话,把其中的单词按字母表顺序输出出来,除去重复的。

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

解题思路:逐个比较即可

//UVA-10815 Andy's First Dictionary#include<iostream>#include<stdio.h>#include<string.h>#include <stdlib.h>  //the hander file of qsort()using namespace std;char word[100000][10000];int cmp(const void *a,const void *b) {    char *_a = (char*)a;    char *_b = (char*)b;    return strcmp(_a, _b);}int main(){    char ch;    int m = 0;    while((ch=getchar())!=EOF)    {        int n = 0;        if ((ch>='a'&&ch<='z'||ch>='A'&&ch<='Z')) {            while((ch>='a'&&ch<='z'||ch>='A'&&ch<='Z')) {                if(ch>='A'&&ch<='Z')                ch=ch+'a'-'A';                word[m][n++] = ch;                ch = getchar();            }            word[m++][n] = '\0';        }    }    qsort(word,m,10000,cmp);    cout << word[0] <<endl;    for (int i = 1; i < m; i++) {         if (strcmp(word[i-1],word[i]))             cout << word[i] <<endl;         else             continue;    }    return 0;}
0 0
原创粉丝点击