Uva-1339Ancient Cipher

Source: Internet
Author: User

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 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.


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
Sample output

I understood the question for a long time and then went to look at other people's ideas,
In addition, the usage of memset () is forgotten, and then the memory occupied by the array is written randomly...
# Include <stdio. h> # include <stdlib. h> # include <string. h> // after learning about quicksort, we need to work hard on Int adjustarray (INT s [], int L, int R) {int I = L, j = R; int x = s [l]; while (I <j) {While (I <J & S [J]> = x) j --; if (I <j) {s [I] = s [J]; I ++;} while (I <J & S [I] <X) I ++; if (I <j) {s [J] = s [I]; j -- ;}} s [I] = x; return I;} void quicksort (int A [], int l, int R) {If (L <r) {int I = adjustarray (A, L, R); quickso RT (A, L, I-1); quicksort (A, I + 1, R) ;}/// this is the merged version, I think people talk about the good http://blog.csdn.net/morewindows/article/details/6684558void quick_sort (INT s [], int L, int R) {If (L <r) {int I = L, j = r, X = s [l]; while (I <j) {While (I <J & S [J]> = x) j --; if (I <j) s [I ++] = s [J]; while (I <J & S [I] <X) I ++; if (I <j) s [j --] = s [I];} s [I] = x; quick_sort (S, L, I-1); quick_sort (S, I + 1, r) ;}} int main () {char S1 [1 10], S2 [110]; int A [26], B [26]; while (scanf ("% S % * C", S1 )! = EOF) {scanf ("% S % * C", S2); int Len = strlen (S1); memset (A, 0, sizeof ()); memset (B, 0, sizeof (B); int I = 0; for (I = 0; I <Len; ++ I) {A [S1 [I]-'a'] ++; B [S2 [I]-'a'] ++;} quick_sort (A, 0, 25 ); quick_sort (B, 0, 25); int num = 0; for (I = 0; I <26; ++ I) {if (a [I] = B [I]) {num ++;} else break;} If (num = 26) {printf ("Yes \ n") ;}else {printf ("NO \ n") ;}} return 0 ;}
View code


Uva-1339Ancient Cipher

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.