uva 10815 - Andy's First Dictionary

#include<iostream>
#include<cctype>
#include<cstdlib>
#include<cstdio>
#include<cstring>
using namespace std;

char word[5001*201][201];

int cmp(const void *a,const void *b){
    return strcmp((char*)a , (char *)b);
}

int main(){
    char ch;
    int i = 0,j = 0;
    while((ch = getchar()) != EOF){
        if(isalpha(ch)){
            word[i][j++] = tolower(ch);
        }
        if(!isalpha(ch) && isalpha(word[i][0])){     //控制条件比较精妙
            word[i++][j] = '\0';
            j = 0;
        }
    }
    qsort(word,i,sizeof(word[0]),cmp);
    puts(word[0]);
    for(int k = 1; k < i; k++){
        if(strcmp(word[k-1],word[k]))
            puts(word[k]);
    }

    return 0;
}

 

posted @ 2015-07-16 17:26  杨永华  阅读(83)  评论(0编辑  收藏  举报