POJ 2159 Ancient Cipher (water)

Source: Internet
Author: User

Ancient Cipher
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 30695 Accepted: 10023

Description

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, ten, 9, 8> to the message "victorious" one gets the Messa GE "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 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 substit Ution and permutation ciphers. 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-do it, so you have to write one.

Input

Input contains the 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 is equal and does not exceed 100.

Output

Output "YES" if the message on the first line of the input file could is the result of encrypting the message on the Secon D line, or "NO" in the other case.

Sample Input

Jwpudjstvpvictorious

Sample Output

YES


Because the order can be changed.
So consider whether you can map. As long as there are letters corresponding to the occurrences of the same number. Then you can get it by mapping.
In particular, an array is opened to record the number of occurrences of each letter ...
Then sort

1 /*************************************************************************2 > File name:code/poj/2159.cpp3 > Author:111qqz4 > Email: [Email protected]5 > Created time:2015 September 23 Wednesday 19:04 34 seconds6  ************************************************************************/7 8#include <iostream>9#include <iomanip>Ten#include <cstdio> One#include <algorithm> A#include <cmath> -#include <cstring> -#include <string> the#include <map> -#include <Set> -#include <queue> -#include <vector> +#include <stack> -#include <cctype> + #defineY1 HUST111QQZ A #defineYn hez111qqz at #defineJ1 CUTE111QQZ - #defineMS (A,X) memset (A,x,sizeof (a)) - #defineLR DYING111QQZ - using namespacestd; - #definefor (i, n) for (int i=0;i<int (n); ++i) -typedefLong LongLL; intypedefDoubleDB; - Const intINF =0x3f3f3f3f; to Const intn= -; + stringSt1,st2; - intLen; the intA[n],b[n]; *  $ Panax Notoginseng BOOLcmpintAintb) - { the     if(A&GT;B)return true; +     return false; A } the intMain () + { - #ifndef Online_judge $Freopen ("In.txt","R", stdin); $   #endif -MS (A,0); -MS (b,0); theCin>>st1>>St2; -Len =st1.length ();Wuyi   //cout<<st1<<endl<<st2<<endl; the     for(inti =0; i < Len; i + +) -     { Wu     intTMP = st1[i]-'A'; -a[tmp]++; AboutTMP = st2[i]-'A'; $b[tmp]++; -     } -     -Sort (a,a+ -, CMP); ASort (b,b+ -, CMP); +   //for (int i = 0; i < i++) cout<< "a[i": "<<a[i]<<" B[i] "<<b[i]<<endl; the  -    BOOLFlag =true; $     for(inti =0; I < -; i++) the     { the     if(a[i]!=B[i]) the     { theFlag =false; -          Break; in     } the     } the    if(flag) About     { thePuts"YES"); the     } the    Else +     { -Puts"NO"); the     }Bayi      the     the #ifndef Online_judge - fclose (stdin); -   #endif the     return 0; the}
View Code

POJ 2159 Ancient Cipher (water)

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.