2009 Latent persons

Source: Internet
Author: User

Lurking Person Title Description

"Problem description"
R and S countries are in the midst of war, the two sides have exchanged spies, sneak into each other's internal, opportunistic action.
After a difficult, latent in S state of R country Spy small C finally found out the code rules of s country Military Code:
1. The original information sent by the military inside the S state is encrypted and sent on the network, the contents of the original information and the encryption
The contents are made up of capital letters ' A '-' Z ' (no other characters, such as spaces).
2. S state has a corresponding "cipher" for each letter. The process of encrypting is to replace all the letters in the original information
The corresponding "Secret word".
3. Each letter only corresponds to a unique "cipher", and different letters correspond to different "secret words". The word "cipher" can
Same as the original letter.
For example, if the word ' a ' is specified as ' a ' and ' B ' is ' C ' (other letters and secret characters), the original letter
"ABA" is encrypted as "ACA".
Now, small C through the inside of the S state network to send an encrypted message and its corresponding original information. Small C
I hope we can decipher the military code of S country through this message. The decoding process of small C is this: scanning the original information, the
The letter X in the An originating information (representing any uppercase letter), finds its corresponding uppercase letter Y in the encrypted message, and considers
In the password Y is the secret of X. This goes on until it stops at one of the following states:
1. All the information is scanned, ' A '-' Z ' all 26 letters have appeared in the original information and obtained the corresponding
"Secret word".
2. All information is scanned, but there is a certain (or some) letter found that does not appear in the original message.
3. There is a clear contradiction or error in the information found in the scan (Code rules that violate the S country code). Cases
If a message "XYZ" is translated into "ABA", it violates the "different letters corresponding to different secret words" rule.
In the small C busy dizzy brain rise, the R State Command sent a telegram, asked him to translate another from S country just
The encrypted information that was intercepted. Now, please help little c: Try to decipher the password by using the information in the insider's hands. Then use the broken
To translate the encrypted information in the telegram.

Enter a description

The 1th Act small c grasps an encrypted message.
The original information corresponding to the encrypted information in line 2nd of the 1th row.
3rd Act R State command requires small c translation of encrypted information.
The input data guarantees that all strings consist only of uppercase ' A '-' Z ', and that the 1th line is equal to line 2nd.

Output Description

If the decryption code stops when 2, 32 cases, please output "Failed" (without quotation marks, note the first letter large
Write, other lowercase).
Otherwise, export the original information obtained by using the password to translate the encrypted information in the telegram.

Sample Input

"Input and output Example 1"
Aa
Ab
Eowie

"Input and output Example 2"

Qwertyuioplkjhgfdsazxcvbn

Abcdefghijklmnopqrstuvwxy

Dsliewo

"Input and output Example 3"
Msrtzcjkpflqyvawbinxuedghooilsmijfrcoppqceunydumpp
Yizsdwahlnovfucerkjxqmgtbppkoiykanzwpllvwmqjfgqyll
Flso

Sample Output

"Input and output Example 1"
Failed

"Input and output Example 2"

Failed

"Input and output Example 3"
NOIP

data range and tips

"Input and Output Example 1 description"
The letters ' A ' and ' B ' in the original message correspond to the same cipher, and the output "Failed".

"Input and Output Example 2 description"
The letter ' Z ' does not appear in the original message and outputs "Failed".

//simulation;#include <cstdio>#include<cstring>#include<string>using namespacestd;intsz[ -]={0},yx[ -]={0},n;Chars1[1002],s2[1002],s[1002];intMain () {scanf ("%s%s", S1,S2); N=strlen (S1);  for(intI=0; i<n;i++){        if(sz[s1[i]-'A']==0|| sz[s1[i]-'A']==s2[i]) sz[s1[i]-'A']=s2[i];//Different letters correspond to different characters, 26 letters one by one correspond;        Else{printf ("failed\n"); return 0; }        if(yx[s2[i]-'A']==0|| s1[i]==yx[s2[i]-'A']) yx[s2[i]-'A']=s1[i];//Ibid.        Else{printf ("failed\n"); return 0; }} scanf ("%s", s); N=strlen (s);  for(Charq='A'; q<='Z'; q++)        if(yx[q-'A']==0){//26 letters must have corresponding secret words;printf"failed\n"); return 0; }     for(intI=0; i<n;i++) {Putchar (Sz[s[i]-'A']); }    return 0;}
View Code

2009 Latent persons

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.