4_1 古老的密码(UVa1339)

Posted 温暖家园(C++进阶)

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了4_1 古老的密码(UVa1339)相关的知识,希望对你有一定的参考价值。

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 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 “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, 10, 9, 8? to 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 was encrypted using permutation cipher. Encrypting the message “VICTORIOUS” 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.

输入:

输入文件包含多个测试案例。它们包括两行。第一行包含刻在板的消息。在加密前,所有的空格和标点符号都拆了,所以
加密的信息只包含大写字母的英文字母。第二行包含原始消息推测被加密在第一行的消息。它也包含的英文字母只有大写字母。输入文件的每行的长度是相等的和不超过100。

输出:

对于每一个测试案例,打印输出一行。输出“是”如果在输入文件的第一行的消息可以在第二行消息加密的结果,或没有在其他情况下。

样例输入:
JWPUDJSTVP
VICTORIOUS
MAMA
ROME
HAHA
HEHE
AAA
AAA
NEERCISTHEBEST
SECRETMESSAGES

样例输出:
YES
NO
YES
YES
NO

以上是关于4_1 古老的密码(UVa1339)的主要内容,如果未能解决你的问题,请参考以下文章

uva1339Ancient Cipher

算法竞赛入门经典 第四章

UVa 1339 - Ancient Cipher

例题4-1-3-古老的密码刽子手的游戏,救济金发放

UVa 1339 Ancient Cipher --- 水题

uva1339