Solution of 11946 - Code Number

Problem Description
source:https://uva.onlinejudge.org/external/119/p11946.html

Adrian and Maria are relatives that live in different towns. As they inhabit a rural area, it is very difficult for them to keep in touch. One way they found to overcome their communication problem was to send a line through their parents that used to visit each other.

 The point is that Adrian and Maria did not want that their parents read their messages, and they decided to create a secret code for the messages. The code is not very sophisticated, but you should keep in mind Adrian and Maria are just children. 

In general, the meaning of a message is based on changing some letters by numbers. Each message is composed by several lines using uppercase letters of the English alphabet, space and punctuation symbols: dot and comma. The letters that are changed by numbers can be seen in the following example; this change is the same for all messages between Adrian and Maria. 

Message in “Code Number”:


 H3LL0 MY L0V3, 1 M H499Y 83C4U53 500N 1 W1LL 83 70 Y0UR 51D3. 7H15 71M3 W17H0U7 Y0U H45 833N 373RN4L. 1 1NV173 Y0U 70 7H3 200 0N3 70 533 7H3 238R42 4ND 60R1L42. 

Decode Message: 

HELLO MY LOVE, I M HAPPY BECAUSE SOON I WILL BE TO YOUR SIDE. THIS TIME WITHOUT YOU HAS BEEN ETERNAL. I INVITE YOU TO THE ZOO ONE TO SEE THE ZEBRAS AND GORILAS. 

Hint: In this example, the relation Number-Letter between the message in “Code Number” and the Decode Message this indicated by the numbers and letters in bold. 

Input 

The first line of input gives the number of test cases, T (1 ≤ T ≤ 30). Each test case represents a message written in Code Number, which is composed by 1 ≤ N ≤ 100 lines and each line cannot exceed 80 characters of length. Two words in the same line are separated by one white space. One blank line separated each test case. 

Output 

For each test case you must print the decoded message. You must print a blank line between each test case. 

Sample Input 


H3LL0 MY L0V3, 1 M H499Y 83C4U53 500N 1 W1LL 83 70 Y0UR 51D3. 7H15 71M3 W17H0U7 Y0U H45 833N 373RN4L. 1 1NV173 Y0U 70 7H3 200 0N3 70 533 7H3 238R45 4ND 60R1L45. 

Sample Output 

HELLO MY LOVE, I M HAPPY BECAUSE SOON I WILL BE TO YOUR SIDE. THIS TIME WITHOUT YOU HAS BEEN ETERNAL. I INVITE YOU TO THE ZOO ONE TO SEE THE ZEBRAS AND GORILAS.


Solution:
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include<stdio.h>
#include<stdlib.h>

using namespace std;

int main()
{
    int t,i,j,len;
    char message[100],c;
    while(scanf("%d",&t)==1)
    {
        getchar();
        for(i=1;i<=t;i++)
        {
            while(gets(message))
            {
                len=strlen(message);
                if (len==0)
                    break ;
                for(j=0;message[j]!='\0';j++)
                {
                    if(message[j]=='0')
                        printf("O");
                    else if(message[j]=='1')
                        printf("I");
                    else if(message[j]=='2')
                        printf("Z");
                    else if(message[j]=='3')
                        printf("E");
                    else if(message[j]=='4')
                        printf("A");
                    else if(message[j]=='5')
                        printf("S");
                    else if(message[j]=='6')
                        printf("G");
                    else if(message[j]=='7')
                        printf("T");
                    else if(message[j]=='8')
                        printf("B");
                    else if(message[j]=='9')
                        printf("P");
                    else
                        printf("%c",message[j]);
                    }
                printf("\n");
                memset(message,'\0',sizeof(message));
            }
            if(i!=t)
                printf("\n");
        }
    }
}
image

No comments:

Post a Comment

Write your comment - Share Knowledge and Experience