UVa-10815-Andy's First Dictionary

AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 1. Elementary Problem Solving :: String


// 10815 - Andy's First Dictionary
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cctype>
using namespace std;

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

int main(void)
{
	string temp;
	int i, c, cnt=0, first=1;
	char s[20], word[5000][20];
	while((c=getchar()), c!=EOF)
	{
		if(isalpha(c))
		{
			if(first)
			{
				temp = "";
				temp += (char)tolower(c);
				first = 0;
			}
			else
			{
				temp += (char)tolower(c);
			}
		}
		else if(temp != "")
		{
			strcpy(s, temp.c_str());
			for(i=0; i<cnt; i++)
				if(strcmp(s, word[i]) == 0)
					break;
			if(i == cnt)
				strcpy(word[cnt++], s);
			temp = "";
			first = 1;
		}
	}
	qsort(word, cnt, sizeof(word[0]), cmp);
	for(i=0; i<cnt; i++)
		cout << word[i] << endl;
	return 0;
}


posted @ 2014-08-23 17:19  颜威  阅读(215)  评论(0编辑  收藏  举报