Algorithm, Data structure/Solved Algorithmic Problem

BAEKJOON 2703 - Cryptoquote

JaykayChoi 2016. 12. 22. 23:28

문제: https://www.acmicpc.net/problem/2703



문제

A cryptoquote is a simple encoded message where one letter is simply replaced by another throughout the message. For example:

  • Encoded: HPC PJVYMIY
  • Decoded: ACM CONTEST

In the example above, H=A, P=C, C=M, J=O, V=N, Y=T, M=E and I=S. For this problem, you will decode messages.

입력

The first line of input contains a single integer N, (1 ≤ N ≤ 1000) which is the number of data sets that follow. Each data set consists of two lines of input. The first line is the encoded message. The second line is a 26 character string of upper case letters giving the character mapping for each letter of the alphabet: the first character gives the mapping for A, the second for B and so on. Only upper case letters will be used. Spaces may appear in the encoded message, and should be preserved in the output string.

출력

For each data set, you should generate one line of output with the following values: The data set number as a decimal integer (start counting at one), a space and the decoded message.

예제 입력 

2
HPC PJVYMIY
BLMRGJIASOPZEFDCKWYHUNXQTV
FDY GAI BG UKMY
KIMHOTSQYRLCUZPAGWJNBVDXEF

예제 출력 

ACM CONTEST
THE SKY IS BLUE

힌트



아스키코드의 기본적인 특징을 이용해 쉽게 풀 수 있는 문제입니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <fstream>
#include <iostream>
#include <cstring>
#include <climits>
#include <algorithm>
 
#include <string>
using namespace std;
 
 
int main()
{        
    int cases;
    cin >> cases;
    for (int c = 0; c < cases; c++)
    {
        char ch;
        cin.get(ch);
        string characters;
        while (cin.get(ch))
        {
            if (ch == '\n')
                break;
            characters += ch;
        }
        string strDecryptionKey;
        cin >> strDecryptionKey;
        
        for (int i = 0; i < characters.length(); i++)
        {
            if (characters[i] != ' ')
                cout << strDecryptionKey[characters[i] - 'A'];
            else
                cout << ' ';
        }
        cout << endl;
    }
 
    return 0;
}
cs