Codeforces gym102222 C. Caesar Cipher 签到

题意:

给定一对用凯撒密码加密的明文和密文,再给你一个密文,让你解密出明文,保证有唯一解。

题解:

对凯撒密码的已知明文攻击,签到题。

#include<iostream>
using namespace std;
char c1[100],c2[100],c3[100];
int t;
int main(){
    int __;
    scanf("%d",&__);
    for(int _=1;_<=__;_++){
        int n,m;
        scanf("%d %d",&n,&m);
        scanf("%s %s",c1,c2);
        t=(c1[0]-c2[0]+26)%26;
        scanf("%s",c3);
        printf("Case #%d: ",_);
        for(int i=0;i<m;i++){
            printf("%c",(c3[i]-'A'+t)%26+'A');
        }
        printf("\n");
    }
    return 0;
}

 

posted @ 2019-08-31 22:42  Isakovsky  阅读(174)  评论(0编辑  收藏  举报