Ancient Cipher (UVA-10340 && POJ-2159)
来源:互联网 发布:战龙三国旗子进阶数据 编辑:程序博客网 时间:2024/05/13 14:08
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 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.
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.
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.
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 could be the result of encrypting the message on the second line, or "NO" in the other case.
Sample Input
JWPUDJSTVPVICTORIOUS
Sample Output
YES
题意:给你两个字符串,可以任意打乱顺序,看是否可以一一对应;
思路:提取每个字母的个数,排序,看是否能相等;
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;int a[30],b[30];string s1,s2;int main(){ while(cin>>s1>>s2) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); int len=max(s1.length(),s2.length()); for(int i=0; i<len; i++) { a[s1[i]-'A']++; b[s2[i]-'A']++; } sort(a,a+26); sort(b,b+26); bool flag=true; for(int i=0; i<26; i++) { if(a[i]!=b[i]) { flag=false; break; } } if(flag) printf("YES\n"); else printf("NO\n"); } return 0;}
阅读全文
0 0
- Ancient Cipher (UVA-10340 && POJ-2159)
- POJ 2159 Ancient Cipher
- poj 2159 : Ancient Cipher
- POJ 2159 Ancient Cipher
- POJ 2159 Ancient Cipher
- poj 2159 Ancient Cipher
- POJ 2159 Ancient Cipher
- POJ 2159 Ancient Cipher
- POJ-2159-Ancient Cipher
- POJ 2159 Ancient Cipher
- poj 2159 Ancient Cipher
- POJ 2159 Ancient Cipher
- POJ 2159 Ancient Cipher
- poj 2159Ancient Cipher
- POJ 2159 Ancient Cipher
- POJ 2159 Ancient Cipher
- POJ 2159 Ancient Cipher
- POJ-2159 Ancient Cipher
- getField 和 getDeclaredField 的区别
- 机器学习中的偏差和方差
- Oracle(创建序列)
- Hibernate知识点
- dubbo问题记录-多注册中心配置错导致爆内存
- Ancient Cipher (UVA-10340 && POJ-2159)
- Android适配三星S8的18.5:9,小米mix全面屏
- Android RecyclerView工作原理分析(下)
- centos 6.5上redis安装与配置
- spring mvc国际化资源实现
- LNMP框架的搭建(nginx的安装与配置)
- require String parameter "password" is not parent
- 20170615的代码
- 在MAC上安装软件,可能不是来自官方的软件,这时需要对来源进行选择,可以使用以下方式打开