Zoj problem set-1858 soundex

Source: Internet
Author: User

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;
 
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.