Time Limit: 2 seconds memory limit: 65536 KB
Soundex coding groups together words that appear to sound alike based on their spelling. For example, "can" and "khawn", "con" and "gone" wocould be equivalent under soundex coding.
Soundex Coding involves translating each word into a series of digits in which each digit represents a letter:
1 represents B, F, P, or V
2 represents C, G, J, K, Q, S, X, or Z
3 represents D or t
4 represents L
5 represents m or N
6 represents R
The letters A, E, I, O, U, H, W, and Y are not represented in soundex coding, and repeated letters with the same code digit are represented by a single instance of that digit. words with the same soundex coding are considered equivalent.
Input
Each line of input contains a single word, all upper case, less than 20 letters long.
Output
For each line of input, produce a line of output giving the soundex code.
Sample Input
Khawn
Pfister
Bobby
Sample output
25
1236
11
Source:University of Waterloo local contest %9.25
# Include <iostream>
# Include <String>
Using NamespaceSTD;
IntMain (Void)
{
StringUword;
While(CIN> uword)
{
IntPrei = 0, crti = 0;
For(IntI = 0; I <uword. Length (); I ++)
{
Switch(Uword [I])
{
Case'B ':Case'F ':Case'P ':Case'V ':
Crti = 1;
If(Prei! = Crti)
{
Cout <crti;
Prei = crti;
}
Break;
Case'C ':Case'G ':Case'J ':Case'K ':Case'Q ':Case'S ':Case'X ':Case'Z ':
Crti = 2;
If(Prei! = Crti)
{
Cout <crti;
Prei = crti;
}
Break;
Case'D ':Case'T ':
Crti = 3;
If(Prei! = Crti)
{
Cout <crti;
Prei = crti;
}
Break;
Case'L ':
Crti = 4;
If(Prei! = Crti)
{
Cout <crti;
Prei = crti;
}
Break;
Case'M ':Case'N ':
Crti = 5;
If(Prei! = Crti)
{
Cout <crti;
Prei = crti;
}
Break;
Case'R ':
Crti = 6;
If(Prei! = Crti)
{
Cout <crti;
Prei = crti;
}
Break;
Default:
Prei = 0;
Break;
}
}
Cout <Endl;
}
Return0;
}