A report on the problem of NOIP2009 T1 latent person

Source: Internet
Author: User

A report on the problem of NOIP2009 T1 latent person

by Medalplus

"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

Analysis

Actually is the string processing, the password and so on the question can use the map to solve, we open the double mapping (cipher, password, cipher, cipher)

First read, see if there are 26 letters, this can be directly used in a bucket

Then fix the mapping relationship, check whether a letter is mapped to 2 letters at the time of update, and if there is output failed, continue to sweep down

Final confirmation direct sweep again, output single-mapped content

Time complexity O (L)

It's still pretty high efficiency.

Code

1#include <iostream>2#include <cstdio>3#include <string>4#include <cstring>5 using namespacestd;6 7 intt1[ -];8 strings1,s2,s;9 Charhash[ -],map[ -];Ten  One intMain () { ACin>>s1>>s2>>s; -UnsignedintI,l,len; -L=s1.size (); thelen=s.size (); -      for(i=0; i<l;i++) -t1[s1[i]-'A']=1; -      for(i=0; i<= -; i++) +       if(!T1[i]) -{printf ("Failed");return 0;} +      for(i=0; i<l;i++)//Processing Mappings A       if((hash[s1[i]-'A']>='A'&& hash[s1[i]-'A']<='Z'&& hash[s1[i]-'A']!=s2[i]) | | (map[s2[i]-'A']>='A'&& map[s2[i]-'A']<='Z'&& map[s2[i]-'A']!=S1[i]))  at{printf ("Failed");return 0;} -       Else -hash[s1[i]-'A']=s2[i],map[s2[i]-'A']=S1[i]; -      for(i=0; i<len;i++) -cout<'A']; -     return 0; in}

Personally, I think it's more concise.

(reproduced please specify the source)

A report on the problem of NOIP2009 T1 latent person

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.