UVA 10815 - Andy's First Dictionary

将单词转换成小写后按照字典序输出。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctype.h>

char word[100010][50] = {'\0'};

int cmp( const void *_p, const void *_q)
{
char *p = ( char *)_p;
char *q = ( char *)_q;
return strcmp( p, q);
}

int main()
{
char ch;
int n = 0, len = 0;
while( true)
{
if( (ch = getchar()) == EOF) break;
if( isalpha( ch) )
word[n][len ++] = tolower(ch);
else
if( isalpha( word[n][0])) {
word[n ++][len] = '\0';
len = 0;
}
}

qsort( word, n, sizeof (word[0]), cmp);
for( int i = 0; i < n; i ++)
if( strcmp( word[i], word[i + 1]))
printf( "%s\n", word[i]);
return 0;
}

 

你可能感兴趣的:(first)