#include<iostream> #include<cstdlib> #include<cstdio> #include<map> #include<cstring> #define db(a) cout << #a << " = " << a << endl; #define foreach(it, l) for(typeof(l.begin()) it = l.begin(); it != l.end(); it++) using namespace std; mapmapa; string procesar_codigo(string palabra){ string res = ""; res += palabra[0]; for(int i = 1; i < palabra.size() && res.size() < 5; i++){ res += (mapa[palabra[i - 1]] != mapa[palabra[i]]) ? mapa[palabra[i]] : ""; } if(res.size() == 5) res = res.substr(0,4); if(res.size() < 4) res += string(4 - res.size(), '0'); return res; } int main(){ string linea; mapa['B'] = "1"; mapa['C'] = "2"; mapa['J'] = "2"; mapa['D'] = "3"; mapa['N'] = "5"; mapa['P'] = "1"; mapa['S'] = "2"; mapa['Q'] = "2"; mapa['T'] = "3"; mapa['R'] = "6"; mapa['F'] = "1"; mapa['K'] = "2"; mapa['X'] = "2"; mapa['L'] = "4"; mapa['V'] = "1"; mapa['G'] = "2"; mapa['Z'] = "2"; mapa['M'] = "5"; mapa['A'] = ""; mapa['U'] = ""; mapa['E'] = ""; mapa['Y'] = ""; mapa['I'] = ""; mapa['W'] = ""; mapa['O'] = ""; mapa['H'] = ""; cout << " NAME SOUNDEX CODE" << endl; while(cin >> linea){ string res = string(9, ' '); res += linea; string aumento = string(25 - linea.size(),' '); res += aumento + procesar_codigo(linea); cout << res << endl; } string s = string(19,' '); s += "END OF OUTPUT"; cout << s << endl; return 0; }
lunes, 24 de octubre de 2011
739 - Soundex Indexing, uva
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario