C - Message Decowding


Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u


Submit   Status



Description



The cows are thrilled because they've just learned about encrypting messages. They think they will be able to use secret messages to plot meetings with cows on other farms.  

Cows are not known for their intelligence. Their encryption method is nothing like DES or BlowFish or any of those really good secret coding methods. No, they are using a simple substitution cipher.  

The cows have a decryption key and a secret message. Help them decode it. The key looks like this:  

yrwhsoujgcxqbativndfezmlpk



Which means that an 'a' in the secret message really means 'y'; a 'b' in the secret message really means 'r'; a 'c' decrypts to 'w'; and so on. Blanks are not encrypted; they are simply kept in place.

 


Input text is in upper or lower case, both decrypt using the same decryption key, keeping the appropriate case, of course.

 



Input



* Line 1: 26 lower case characters representing the decryption key  

* Line 2: As many as 80 characters that are the message to be decoded  



Output



* Line 1: A single line that is the decoded message. It should have the same length as the second line of input.  



Sample Input



eydbkmiqugjxlvtzpnwohracsf Kifq oua zarxa suar bti yaagrj fa xtfgrj



Sample Output



Jump the fence when you seeing me coming



解题报告:题目大意给出a到z的对应的密码,然后再给你一串字符,让你给出对应的译码,注意,若给出的字母是大写则解码后也应为大写形式,空格不译码;

第一行是26个小写字母对应的密匙,第二行给出要译码的字符串。

解题思路:

用一个数组存储这26个英文字母的密匙,a[0]的值代表a的密匙,,依次类推。注意,你若用scanf("%c",&c)读取字符的话,读完第一行的一定要用一下getchar()把第一行的回车读取,否则会出现PE错误。

代码:

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    char a[26],c;
    for(int i=0;i<26;i++)
    cin>>a[i];
    getchar();
    while(scanf("%c",&c)!=EOF)
    {
        if(c>='a'&&c<='z')
        cout<<a[c-'a'];
        else
        if(c>='A'&&c<='Z')
        cout<<char(a[c-'A']-32);
        else
        cout<<c;
    }
    //cout<<endl;
    return 0;

}