UVA 1339 Ancient Cipher

Source: Internet
Author: User

Original question:
Ancient Roman Empire had a strong government system with various departments, including a Secret Service department. Important documents were sent between provinces and the capital in encrypted form to prevent eavesdropping. The most popular ciphers in those times were so called substitution cipher and permutation cipher. Substitution cipher Changes all occurrences the letter to some Substitutes for all letters must is different. For some letters substitute-coincide with the original letter. For example, applying substitution cipher This changes all letters from ' A ' to ' Y ' to the next ones in the alphabet, and C Hanges ' Z ' to ' A ', the message "victorious" one gets the message "WJDUPSJPVT". Permutation cipher applies some permutation to the letters of the message. For example, applying the Permutation⟨2,1,5,4,3,7,6,10,9,8⟩to the message "victorious" one gets the message Ivotcirsuo ".
It is quickly noticed that being applied separately, both substitution cipher and permutation
Cipher were rather weak. But when being combined, they were strong enough for those times. Thus, the most important messages were first encrypted using substitution cipher, and then the result is encrypted using Permutation cipher. Encrypting the Message "victorious" with the combination of the ciphers described above one gets the message "JWPUDJSTVP".
Archeologists has recently found the message engraved on a stone plate. At the first glance it
Seemed completely meaningless, so it is suggested that the message is encrypted with some substitution and permutation c Iphers. They has conjectured the possible text of the original message that is encrypted, and now they want to check their conje Cture. They need a computer program to does IT,SO you has to write one.
Input
Input file contains several test cases. Each of them consists of lines. The first line contains the
Message engraved on the plate. Before encrypting, all spaces and punctuation marks were removed, so the encrypted message contains only capital letters O f the 中文版 alphabet. The second line contains the original message, which is conjectured to being encrypted in the message on the first line. It also contains only capital letters of the Chinese alphabet.
The lengths of both lines of the input file is equal and does not exceed 100.
Output
For each test case, print one output line. Output ' YES ' if the message on the first line of the input file
Could is the result of encrypting the message on the second line, or ' NO ' in the other case.
Sample Input
Jwpudjstvp
Victorious
MAMA
ROME
HAHA
HEHE
Aaa
Aaa
Neercisthebest
Secretmessages
Sample Output
YES
NO
YES
YES
NO
English:
Give you two strings, for whether these two characters can pass a fixed conversion rule, one of the strings after the conversion, and another string after the same reflow.

#include <bits/stdc++.h>
using namespace std;
int mark1[27],mark2[27];
int main ()
{
    Ios::sync_with_stdio (false);
    string s1,s2;
    while (CIN>>S1>>S2)
    {
        memset (mark1,0,sizeof (MARK1));
        memset (mark2,0,sizeof (MARK2));
        for (auto x:s1)
            mark1[x-65]++;
        for (auto x:s2)
            mark2[x-65]++;
        Sort (mark1,mark1+26);
        Sort (mark2,mark2+26);
        int flag=0;
        for (int i=0;i<26;i++)
        if (Mark1[i]!=mark2[i])
        {
            flag=1;
            break;
        }
        if (flag)
            cout<< "NO" <<endl;
        else
            cout<< "YES" <<endl;
    }
    return 0;
}

Answer:
intends to Rujia the purple book to do all over again, and read the book again. The problem is very simple, just practice the code. If a string can be converted and then re-sorted after a certain sequence, then the number of letters in the two strings will appear in the same order.

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.