11: lurks, 11 lurks

Source: Internet
Author: User

11: lurks, 11 lurks

I personally think this question is a comprehensive and difficult question in the string.

Strong requirement on data search capability of contestants

I used the bucket layout idea when doing this question.

Let's talk about the code. The whole network is the simplest.

11: lurks
  • View
  • Submit
  • Statistics
  • Question
Total time limit:
1000 ms
 
Memory limit:
65536kB
Description

The R and S countries are in war, and both sides send spies to each other to serve the other party.

After the hardships, the R-state spy C lurking in S finally figured out the coding rules of S-state military passwords:

1. The original information to be sent by the S military is encrypted and sent on the network, the content of the original information and the encrypted content are composed of uppercase letters 'a'-'Z' (without spaces or other letters ).

2. Country S specifies the corresponding "password" for each letter ". The encryption process is to replace all the letters in the original information with the corresponding "password ".

3. Each letter corresponds to only one unique "password", and different letters correspond to different "password ". The password can be the same as the original letter.

For example, if the password of 'A' is set to 'A' and that of 'B' is 'C' (other letters and characters are omitted ), the original information "ABA" is encrypted as "ACA ".

Now, Mr. C has mastered an encrypted message sent from the S-country network and its original information through the internal line. Small C hopes to use this information to crack S's military password. The decryption process of small C is as follows: scan the original information. For the letter x in the original information (representing any capital letter), find the corresponding capital letter y in the encrypted information, in the password, y is the password of x. This continues until it stops in the following status:

1. After scanning all the information, all 26 letters of 'A'-'Z' have appeared in the original information and obtained the corresponding "password ".

2. All information is scanned, but some (or some) letters are not found in the original information.

3. The scanned information contains obvious self-contradictions or errors (violating the S-pass password encoding rules ). For example, if a piece of information "XYZ" is translated as "ABA", it violates the rule that "different letters correspond to different characters.

When Mr. C was so busy, the R State Command sent a telegram asking him to translate another piece of encrypted information just captured from country S. Now, please help little C: Try to decrypt the password through the internal information. Then, use the deciphering password to translate the encrypted information in the telegram.

Input
There are 3 rows in total, and each row is a string between 1 and 100 characters.
1st. A piece of encryption information that C has mastered.
2nd the original information corresponding to the encrypted information of row 1st.
3rd behavior: The R State Command requested the encrypted information translated by Xiao C.
Input data ensures that all strings only consist of uppercase letters 'a'-'Z', and the length of the 1st rows is equal to that of the 2nd rows.
Output
A total of 1 rows.
If there are two or three cases when the password is stopped, please output "Failed" (excluding quotation marks, note that the first letter is in upper case, and other lower case ).
Otherwise, output the original information obtained after the encrypted information in the telegram is translated using the password.
Sample Input
Example #1: AAABEOWIE example #2: QWERTYUIOPLKJHGFDSAZXCVBNABCDEFGHIJKLMNOPQRSTUVWXYDSLIEWO example #3: Example
Sample output
Example #1: Failed sample #2: Failed sample #3: NOIP
Prompt
Input and Output Example 1: The letters 'A' and 'B' in the original information correspond to the same password, and the output is "Failed ".

Input and Output Example 2: The letter 'Z' does not appear in the original information, and the output is "Failed ".
Source
Question 1 in NOIP2009 semi-finals
1/* 2 AA ciphertext QWERTYUIOPLKJHGFDSAZXCVBN 3 AB plaintext ABCDEFGHIJKLMNOPQRSTUVWXY 4 EOWIE encrypted information to be translated DSLIEWO 5 */6 # include <iostream> 7 # include <cstdio> 8 # include <cstring> 9 using namespace std; 10 char ming [100001]; // The plaintext 11 char mi [100001]; // The ciphertext 12 char a [100001]; // The information to be decrypted 13 char zd [100001]; // ciphertext dictionary. Bucket 14 char find_zm [10001]; // you can check whether all 26 letters contain 15 int main () 16 {17 scanf ("% s", & mi ); 18 scanf ("% s", & ming); 19 scanf ("% s", & a); 20 int l = strlen (mi ); // dictionary length 21 int la = strlen (a); // ciphertext length 22 for (int I = 0; I <= l; I ++) 23 {24 if (zd [(int) mi [I] = 0) | (zd [(int) mi [I] = ming [I]) 25 zd [(int) mi [I] = ming [I]; // zd [ciphertext] = Corresponding plaintext 26 else27 {28 cout <"Failed"; 29 return 0; 30} 31} // search for plaintext conflict 32 for (int I = 0; I <= l; I ++) 33 {34 find_zm [(int) ming [I] ++; // a letter 35} 36 for (int I = 65; I <= 90; I ++) appears) 37 {38 if (find_zm [I] = 0) 39 {40 cout <"Failed"; 41 return 0; 42} 43} // determine whether a letter does not appear 44 for (int I = 0; I <la; I ++) 45 {46 a [I] = zd [(int) a [I]; 47} 48 puts (a); 49 // int s = sizeof (zd ); 50 return 0; 51}

 

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.