Ultraviolet A 1339 cipher ent Cipher

Source: Internet
Author: User

Ancient Cipher


Specified ent Roman Empire had a strong government system with varous parameters, 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 of each letter to some other letter. substitutes for all letters must be different. for some letters substitute letter may coincide with the original letter. for example, applying substitution cipher that changes all letters from'A'To'Y'To the next ones in the alphabet, and changes'Z'To'A', To the message''Ubunious''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''Ubunious''One gets the message''Ivotcirsuo''. It was 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 was encrypted using permutation cipher. encrypting the message''Ubunious''With the combination of the ciphers described above one gets the message''Jwpudjstvp''. Archeologists have recently found the message engraved on a stone plate. at the first glance it seemed completely meaningless, so it was suggested that the message was encrypted with some substitution and permutation ciphers. they have conjectured the possible text of the original message that was encrypted, and now they want to check their conjecture. they need a computer program to do it, so you have to write one.

Input input file contains several test cases. each of them consists of two 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 of the English alphabet. the second line contains the original message that is conjectured to be encrypted in the message on the first line. it also contains only capital letters of the English alphabet. the lengths of both lines of the input file are equal and do 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 cocould be the result of encrypting the message on the second line, or' No'In the other case. sample input
JWPUDJSTVPVICTORIOUSMAMAROMEHAHAHEHEAAAAAANEERCISTHEBESTSECRETMESSAGES
Sample output
YESNOYESYESNO

Give two strings, B can rearrange B and map each letter to another letter to get A. Because a can rearrange the order of appearance, you don't have to worry about the number of occurrences of each letter in AB in the array. sort the arrays. If the two arrays are identical, B can be converted to;

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int N = 105;char a[N], b[N];int main(){    while (scanf ("%s%s", a, b) != EOF)    {        int ca[26] = {0}, cb[26] = {0}, l = strlen (a), i;        for (i = 0; i < l; ++i)        {            ++ca[a[i] - 'A'];            ++cb[b[i] - 'A'];        }        sort (ca, ca + 26);        sort (cb, cb + 26);        for (i = 0; i < 26; ++i)            if (ca[i] != cb[i]) break;        printf (i == 26 ? "YES\n" : "NO\n");    }    return 0;}


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.