1071 Latent persons

Source: Internet
Author: User

Difficulty: popularity/improvement-

topic Type: analog

Number of submissions: 3

knowledge Involved: string

Title 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. S State Military internal to send the original information is encrypted and sent over the network, the contents of the original information and the content of the encryption is composed of capital letters ' A '-' Z ' (no spaces and other characters).

2. S state has a corresponding "cipher" for each letter. The process of encrypting is to replace all the letters in the original information with their corresponding "secret words".

3. Each letter only corresponds to a unique "cipher", and different letters correspond to different "secret words". "Ciphertext" can be the same as the original letter.

For example, if the word ' a ' is specified as ' a ', ' B ' is ' C ' (other letters and ciphertext), then the original information "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 hopes to be able to decipher the military code of S country through this message. The decoding process of small C is this: scanning the original information, for the original information in the letter x (representing any capital letter), find its corresponding capital letter Y in the encrypted information, and think in the password y is the secret of X. This goes on until it stops at one of the following states:

1. After all the information has been scanned, ' A '-' Z ' all 26 letters have appeared in the original message and obtained the corresponding "ciphertext".

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 small C busy dizzy brain rise, the R State Command sent a telegram, asked him to translate another from the S country just intercepted the encrypted information. Now, please help little C: Try to decipher the password by using the information in the insider's hands. Then use the decoded password to translate the encrypted information in the telegram.

Input/output format

Input format:

A total of 3 rows, each of which behaves as a string between 1 and 100 in length.

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 format:

A total of 1 rows.

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.

Input and Output Sample input example # #:
AA AB Eowie
Sample # # of output:
Failed
Input Sample #:
Qwertyuioplkjhgfdsazxcvbn Abcdefghijklmnopqrstuvwxy Dsliewo
Output Example #:
Input Sample # #:
Output Sample # #:
NOIP

Code:
1#include <iostream>2#include <string>3#include <cstring>4#include <algorithm>5 using namespacestd;6 //Check Weight7 intMain () {8     stringThe Ori;9     stringencrypt;Ten     strings; OneCin>>ori>>encrypt>>s; A     inta[ -]; -Memset (A,0,sizeof(a)); -     inti; the      for(i =0; I < ori.length (); i++){ -         if(!a[ori[i]- -]) -a[ori[i]- -] = encrypt[i]- -; -         Else if(a[ori[i]- -]! = encrypt[i]- -){ +cout<<"Failed"<<endl;//Scenario 3 -             return 0; +         }     A     } at      for(i =1; I < -; i++){ -         if(!A[i]) { -cout<<"Failed"<<Endl; -             return 0;//Scenario 2 -         } -     } in     intcopy[ -];  -      for(i =1; I < -; i++) toCopy[i] =A[i]; +Sort (Copy, copy+ -); -      for(i =1; I < -; i++){ the         if(Copy[i] = = copy[i+1]){ *cout<<"Failed"<<Endl; $             return 0;Panax Notoginseng         } -}//Check Weight the      for(i =0; I < s.length (); i++){ +         Cout<<char (a[s[i]-64]+64); A     } the     return 0; +}
Note:
Note is the one by one mapping, the first commit is not to pay attention to full firing situation. It seems better to write in map, but I won't. The method of checking the weight is the first sort and then check the weight. Then a problem has not been solved, finally
Found to be char a[100] cannot write directly cout<<a; although several sets of data were tested without error ...

Please also reprint the use of map:

Map is a standard C + + container, she provides a very good one-to-one relationship, in some programs to build a map can play a multiplier effect, summed up some map basic simple and practical operation!
1. Map the most basic constructor function;
map<string, int >mapstring; Map<int, String >mapint;
Map<sring, char>mapstring; map< Char,string>mapchar;
Map<char,int>mapchar; Map<int, Char >mapint;

2. Map add data;

Map<int,string> maplive;
1.maplive.insert (pair<int,string>(102, "aclive"));
2.maplive.insert (map<int,string>::value_type(321, "Hai"));
3, maplive[112]= "April";//map the simplest and most common inserts to add!
Find the elements in the 3,map:

The Find () function returns an iterator that points to an element with a key value, and returns an iterator to the tail of the map if it is not found.

   map<int, string >::iterator l_it;;  
   l_it=maplive.find ();
   if (L_it==maplive.end ())
                 cout<< "We do not find" <<endl;
   else cout<< "wo find" <<endl;
Deletion of elements in 4,map:
    If you delete the    map<int,
>::iterator, String l_it;
   l_it=maplive.find (112);
   if (L_it==maplive.end ())
        cout<< " We do not find "<<endl;"
   else  maplive.erase (l_it);   //delete 112;
use of swap in 5,map:
Swap in   map is not an element exchange in a container, but a two container exchange;
  for Example:
  # Include <map>
   #include <iostream>

using namespace Std;

int main ()
{
Map <int, int> M1, M2, M3;
Map <int, Int>::iterator M1_iter;

M1.insert (Pair <int, int> (1, 10));
M1.insert (Pair <int, int> (2, 20));
M1.insert (Pair <int, int> (3, 30));
M2.insert (Pair <int, int> (10, 100));
M2.insert (Pair <int, int> (20, 200));
M3.insert (Pair <int, int> (30, 300));

cout << "The original map M1 is:";
for (M1_iter = M1.begin (); M1_iter! = M1.end (); m1_iter++)
cout << "" << m1_iter->second;
cout << "." << Endl;

This is the member function version of Swap
M2 is said to be the argument map; M1 the target map
M1.swap (m2);

   cout << "after swapping with M2, map M1 is:";
   for (m1_iter = M1.begin (); M1_iter! = M1.end (); m1_iter++)
     &nb Sp;cout << "<< M1_iter, second;
      cout  << "." << Endl;
   cout << "after swapping with M2, map m2 is:";
   for (m1_iter = M2.begin (); M1_iter! = M2.end (); m1_iter++)
     &nb Sp;cout << "<< M1_iter, second;
      cout  << "." << Endl;
   //This is the specialized template version of Swap
   swap (M1, M3);

cout << "After swapping with M3, map M1 is:";
for (M1_iter = M1.begin (); M1_iter! = M1.end (); m1_iter++)
cout << "<< M1_iter, second;
cout << "." << Endl;
}

Sort problem with 6.map:
The elements in map are automatically sorted by key in ascending order, so you cannot use the sort function for map:
For example:
#include <map>
#include <iostream>

using namespace Std;

int main ()
{
Map <int, int> M1;
Map <int, Int>::iterator M1_iter;

M1.insert (Pair <int, int> (1, 20));
M1.insert (Pair <int, int> (4, 40));
M1.insert (Pair <int, int> (3, 60));
M1.insert (Pair <int, int> (2, 50));
M1.insert (Pair <int, int> (6, 40));
M1.insert (Pair <int, int> (7, 30));

cout << "The original map M1 is:" <<endl;
for (M1_iter = M1.begin (); M1_iter! = M1.end (); m1_iter++)
cout << m1_iter->first<< "" <<m1_Iter->second<<endl;

}
The original map M1 is:
1 20
2 50
3 60
4 40
6 40
7 30
Please press any key to continue ...

7, the basic operation function of map:
C + + maps is an associative container that contains "keyword/value" pairs
Begin () returns an iterator pointing to the map header
Clear () Delete all elements
COUNT () returns the number of occurrences of the specified element
Empty () returns True if Map is empty
End () returns an iterator pointing to the end of the map
Equal_range () returns an iterator to a special entry
Erase () Delete an element
Find () finds an element
Get_allocator () returns the map's Configurator
Insert () Inserts an element
Key_comp () returns the function that compares the element key
Lower_bound () returns the key value >= the first position of a given element
Max_size () returns the maximum number of elements that can be accommodated
Rbegin () returns a reverse iterator pointing to the tail of the map
Rend () returns a reverse iterator pointing to the map header
Size () returns the number of elements in the map
Swap () Swap two maps
Upper_bound () returns the key value > the first position of a given element
Value_comp () returns a function that compares the element value

1071 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.