Poj2159 comment ent Cipher

Source: Internet
Author: User
Ancient Cipher
Time limit:1000 ms   Memory limit:65536 K
Total submissions:22896   Accepted:7703

Description

Your ent Roman Empire had a strong government system with varous parameters, choose a Secret Service Department. Important documents ents were sent between provinces and the capital in your form to prevent versions. The most popular ciphers 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 "Too IOUs" 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 "Too IOUs" 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 "Too IOUs" with the combination of the ciphers described above one gets the message "Too pudjstvp ".
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 contains 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
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 are equal and do not exceed 100.

Output

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

JWPUDJSTVPVICTORIOUS

Sample output

YES

Source

Northeastern Europe 2004 was about letter replacement and was quickly written. It passed the test case above, but wa was the first to submit it. I was very depressed. Later I found that I did not understand the subject. Switching from A-Z to B-A is just an example of the question, not saying it must be such a change. Therefore, a can be mapped to B, but C can also be mapped to Z. We do not know which letter is mapped. Second, after the ing, the sequence replacement is performed, and this replacement array is unknown. Therefore, it is impossible to determine whether the given characters are consistent with the given results after being transformed. After careful analysis, it is found that the result of any letter ing is unique. If the number of X in the text is N, there must be a letter in the password after X transformation, therefore, the probability of its appearance must be equal to that of X in the plain text. The Code is as follows:
#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>using namespace std;int main(){    const int MAX = 101;    char a[MAX];    char b[MAX];    char cnta[26],cntb[26];    memset(cnta,0,26);    memset(cntb,0,26);    scanf("%s%s",a,b);    for(int i=0;i<strlen(a);i++)        cnta[a[i]-'A']++;    for(int i=0;i<strlen(b);i++)        cntb[b[i]-'A']++;    int flag = 1;    sort(cnta,cnta+26);    sort(cntb,cntb+26);    for(int i=0; i<26; i++)    {        if(cnta[i]!=cntb[i])            {                flag = 0;                break;            }    }    if(flag)        printf("YES");    else        printf("NO");    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.