Monday, September 28, 2015

UVa 10815 - Andy's First Dictionary

// UVa 10815 - Andy's First Dictionary

#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

bool letter(char c) {
	return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
}

int main() {
	map<string, bool> taken;
	vector<string> v;
	string word;
	while (cin >> word) {
		for (int i = 0; i < word.length(); i++) {
			if (letter(word[i])) {
				int j = i + 1;
				while (j < word.length() && letter(word[j]))
					j++;
				string w = word.substr(i, j - i);
				for (int k = 0; k < w.length(); k++)
					if (w[k] >= 'A' && w[k] <= 'Z')
						w[k] = w[k] - 'A' + 'a';
				if (!taken[w]) {
					taken[w] = true;
					v.push_back(w);
				}
				i = j;
			}
		}
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << endl;

	return 0;
}

No comments:

Post a Comment