POJ 2159 解题报告

一、substitution 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".

“移位”只是置换密码的一种,只要满足“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".

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

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

 1 //Code name: POJ2159
2 //OJ: POJ 2159
3 //Language: ANSI C (VS2010)
4 //10-14-2011
5 //Status: AC
6 #include<stdio.h>
7 #include<string.h>
8 #include<stdlib.h>
9 const int MAXSIZE=110;
10 int cmp(const void *a, const void *b)
11 {
12 return (*(int*)a- *(int*)b);
13 }
14 int main(){
15 char arr[2][MAXSIZE];
16 int cnt1[26],cnt2[26];
17 char len1,len2,i,j,flag;
18 while(gets(arr[0])!=NULL && gets(arr[1])!=NULL)
19 {
20 len1 =strlen(arr[0]); len2 = strlen(arr[1]);
21 if(len1!=len2) {
22 printf("NO\n");
23 continue;
24 }
25 memset(cnt1,0, sizeof cnt1);
26 memset(cnt2,0, sizeof cnt2);
27 for(i=0; i<len1;i++)
28 {
29 cnt1[arr[0][i]-'A']++;
30 cnt2[arr[1][i]-'A']++;
31 }
32 qsort(cnt1,26,sizeof cnt1[0], cmp);
33 qsort(cnt2,26,sizeof cnt2[0], cmp);
34 for( i=0;i<26 && cnt1[i]==cnt2[i];)
35 i++;
36 if(i<26)printf("NO\n");
37 else printf("YES\n");
38 }
39 return 0;
40 }



转载于:https://www.cnblogs.com/Steven7Gao/archive/2011/10/14/2212652.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值