Ancient Cipher
Ancient Roman Empire had a strong government system with various departments, including a Secret Service department. I Mportant documents were sent between provinces and the capital in encrypted form to prevent eavesdropping. The most popular ciphers in those times were so calledSubstitution cipher andPermutation 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 changes 'Z' to 'A', to the message 'Victorious"One gets the message"wjdupsjpvt". Permutation cipher applies some permutation to the letters of the message. For example, applying the permutation2, 1, 5, 4, 3, 7, 6, ten, 9, 8To the message 'Victorious"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 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.
InputInput 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.Outputfor 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
Jwpudjstvpvictoriousmamaromehahaheheaaaaaaneercisthebestsecretmessages
Sample Output
Yesnoyesyesno
Test instructions give two strings A, a, can I rearrange B and then map each letter to a letter to get a because you can rearrange the order of occurrence without considering the number of times that each letter of AB is only to be present in an array and then sorted in arrays if the resulting two arrays are completely the same B can be converted to A;
#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 + +); Sort (CB, CB + +); for (i = 0; i < ++i) if (ca[i]! = Cb[i]) break; printf (i = = 26?) "yes\n": "no\n"); } return 0;}
UVa 1339 Ancient Cipher