ACM (TJU) : 1326


// http://acm.tju.edu.cn/toj/showp1326.html

#include <stdio.h>
#include <string.h>

int code;

int convert (char x)
{
    char str1 [] = "BFPV";
    char str2 [] = "CGJKQSXZ";

    if ( strchr (str1, x) )
        return 1;

    if ( strchr (str2, x) )
        return 2;

    if ( x == 'D' || x == 'T' )
        return 3;

    if ( x == 'L' )
        return 4;

    if ( x == 'M' || x == 'N' )
        return 5;

    if ( x == 'R' )
        return 6;

    return 0;
}

int main ()
{
    char input [25];

    while ( gets (input) ) {
        code = 0;

        for ( int i = 0; input [i] != 0; i++ ) {
            int temp = convert (input [i]);

            if ( temp && temp != code )
                printf ("%d", temp);

            code = temp;
        }

        printf ("\n");
    }

    return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s