Thursday, June 25, 2015

UVa 10260 - Soundex

// UVa 10260 - Soundex

#include <iostream>
#include <string>
using namespace std;

char lette[26] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };

char sound[26] = { '0', '1', '2', '3', '0', '1', '2', '0', '0', '2', '2', '4', '5', '5', '0', '1', '2', '6', '2', '3', '0', '1', '0', '2', '0', '2' };

int main() {

	string st;
	while (cin >> st) {
		string soundex = "";
		for (int i = 0; i < st.length(); i++)
			if (sound[st[i] - 'A'] != '0' && (i == 0 || sound[st[i] - 'A'] != sound[st[i - 1] - 'A']))
				soundex.push_back(sound[st[i] - 'A']);
		cout << soundex << endl;
	}

	return 0;
}

No comments:

Post a Comment