POJ 2159 : Ancient Cipher - 密码模拟
来源:互联网 发布:创维网络电视机顶盒 编辑:程序博客网 时间:2024/06/05 19:25
题意:
含义是指:将任意字母替换为任意一个字母,只要不出现多个字母替换成同一个就可以,即为一一映射。
因此,我们只需要判断两个字符含有的不同的字母数量以及对应出现的次数都相同就行了。
分析:
“移位”只是置换密码的一种,只要满足“Substitutes for all letters must be different.”就是置换了,比如
A->B
C->H
Z->D
对于这道题,input:
AAABB
CCCEE
应输出
YES
所以明文与密文的“字母频率的数组”应该是一样的,即明文中某字母出现8次,密文中也必须有某个字母出现8次。
所以字母种类,字母频率同时相等时,即被破解。
permutation cipher(排列密码):
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" on
明文随机排列,所以字母种类和频率都不变。
对于这道题,排列密码考虑和不考虑对解题无影响!”
另:
http://blog.csdn.net/lyy289065406/article/details/6642586
2159Accepted696K47MSG++550B
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>using namespace std;int main(){char en[105],ans[105];int a[30],b[30],i;while(~scanf("%s",en)){scanf("%s",ans);int l=strlen(en);memset(a,0,sizeof(a));for(i=0;i<l;i++)a[ans[i]-'A']++;memset(b,0,sizeof(b));for(i=0;i<l;i++)b[en[i]-'A']++;sort(a,a+30);sort(b,b+30);for(i=0;i<30;i++)if(a[i]!=b[i])break;if(i<30)printf("NO\n");elseprintf("YES\n");}return 0;}
0 0
- 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 2159 Ancient Cipher
- POJ 2159 Ancient Cipher
- POJ 2159 Ancient Cipher
- poj 2159Ancient Cipher
- POJ 2159 Ancient Cipher
- POJ 2159 Ancient Cipher
- java写文件时,输出不完整的原因以及解决方法close()或flush()
- POJ 2480 : Longge\'s problem - gcd之和
- POJ 3696 : The Luckiest number - 欧拉函数,快速幂[数论好题]
- POJ 2183 : Bovine Math Geniuses - 平方取尾法
- POJ 1107 : W\'s Cipher - 密码,字符串模拟
- POJ 2159 : Ancient Cipher - 密码模拟
- POJ 3518 : Prime Gap - 素数筛
- POJ 1032 : Paliament - 整数分解
- POJ 1607 /ZOJ 1216 : Deck - 整齐输出
- POJ 3132 / ZOJ 2822 : Sum of Different Primes - 动态规划,01背包,素数筛
- POJ 3012 : A Number from Yanghui Triangle - 快速幂;推公式
- ZOJ 1649 : Rescue - BFS
- ZOJ 2913 : Bus Pass - BFS
- 单行函数测试