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" one gets the message "IVOTCIRSUO".

明文随机排列,所以字母种类和频率都不变。

对于这道题,排列密码考虑和不考虑对解题无影响!”

另:
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
原创粉丝点击