Poj2159 comment ent Cipher
Preface
The English language is poor, and the ac is hard to learn 555. For example, the water question recommended by Daniel is very excited. After reading it, I feel wrong when preparing to write the code. I decided to go to the comment area and read = pitfall. Fortunately, there is no direct code, and the question is directly understood wrong! Do you understand this, comrades? → _ →
Question
Ancient Cipher
Time Limit: 1000 MS Memory Limit: 65536 K
Total Submissions: 29640 Accepted: 9684
Description
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 "various" 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 "delicious" 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 "refreshing" with the combination of the ciphers described above one gets the message "Quit 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 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 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
JWPUDJSTVP
VICTORIOUS
Sample Output
YES
Analysis
Here, I will share my post in the forum with you:
If you do not understand the meaning of this question, it is definitely not a question of water, but it is a little bit of water if you understand it.
The key is understanding of replacement encryption and replacement encryption. the example given in the question may mislead you into the misunderstanding: Replacement encryption is based on certain rules. So you will easily think of sorting first and looking for the gap between the two strings. If the difference is the same, YES ..
In fact, there is no "regular" to replace encryption "! A can correspond to any 26 letters.
If you do not know, it means that the White List does not exist.
So the same standard is whether the initial length of two strings is the same. whether the frequency distribution is the same (no matter which letter frequency, as long as the frequency is arranged from small to large, the two strings are exactly the same)
For example:
Abbccc
Mqqbbb
YES, the frequency is 1 2 3
Aabbcc
Mnnjjj
The NO frequency is 2 2 2 and 1 2 3, respectively.
Okay. That's all.
Code
Then, the code... Step by step
#include
#include
#include char s1[105], s2[105];int main(){ gets(s1); gets(s2); int len1 = strlen(s1); int len2 = strlen(s2); if (len1 != len2) { printf("NO\n"); return 0; } int a[26]={0}; int b[26]={0}; int i; for(i=0; i