Caesar Cipher (2018-2019 ACM-ICPC, China Multi-Provincial Collegiate Programming Contest)(The 2019 A
作者:互联网
In cryptography, a Caesar cipher, also known as the shift cipher, is one of the most straightforward and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions up (or down) the alphabet.
For example, with the right shift of 1919, A would be replaced by T, B would be replaced by U, and so on. A full exhaustive list is as follows:
- The plaintext: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z;
- The ciphertext: T U V W X Y Z A B C D E F G H I J K L M N O P Q R S.
Now you have a plaintext and its ciphertext encrypted by a Caesar Cipher. You also have another ciphertext encrypted by the same method and are asked to decrypt it.
InputThe input contains several test cases, and the first line is a positive integer TT indicating the number of test cases which is up to 5050.
For each test case, the first line contains two integers nn and m (1≤n,m≤50)m (1≤n,m≤50) indicating the length of the first two texts (a plaintext and its ciphertext) and the length of the third text which will be given. Each of the second line and the third line contains a string only with capital letters of length nn, indicating a given plaintext and its ciphertext respectively. The fourth line gives another ciphertext only with capital letters of length mm.
We guarantee that the pair of given plaintext (in the second line) and ciphertext (in the third line) is unambiguous with a certain Caesar Cipher.
OutputFor each test case, output a line containing Case #x: T, where x is the test case number starting from 11, and T is the plaintext of the ciphertext given in the fourth line.
Example input Copy1output Copy
7 7
ACMICPC
CEOKERE
PKPIZKC
Case #1: NINGXIA
分析:(签到题)看完第一感觉,打表,然后分密文左移得到明文还是右移得到明文,密文-明文 > 0 左移减法 ,反之 右移加法。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
#define pq priority_queue<int>
#define pql priority_queue<ll>
#define pqn priority_queue<node>
#define v vector<int>
#define vl vector<ll>
#define lson rt<<1, l, m
#define rson rt<<1|1, m+1, r
#define read(x) scanf("%d",&x)
#define lread(x) scanf("%lld",&x);
#define pt(x) printf("%d\n",(x))
#define yes printf("YES\n");
#define no printf("NO\n");
#define gcd __gcd
#define cn cin>>
#define ct cout<<
#define ed <<endl;
#define ok return 0 ;
#define over cout<<endl;
#define rep(j,k) for (int i = (int)(j); i <= (int)(k); i++)
#define input(k) for (int i = 1; i <= (int)(k); i++) {cin>>a[i] ; }
#define mem(s,t) memset(s,t,sizeof(s))
#define re return 0;
#define TLE std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod(x) ((x)%9973)
#define test cout<<" ++++++ "<<endl;
typedef long long ll;
const int INT=1e6+5;
const int maxn=10000+5;
const int len = 1e5+5;
int main() { int t,n,k; cin>>t; string s="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; for(int kk=1;kk<=t;kk++) { string str,sub,ch; cin>>n>>k; cin>>str>>sub>>ch; n=sub[0]-str[0]; cout<<"Case #"<<kk<<": "<<endl; if(n>=0) { rep(0,ch.size()-1) ct s[ 26+ch[i]-'A'-n ]; } else { n=-n; rep(0,ch.size()-1) ct s[ ch[i]-'A'+n ]; }
over; } ok; }
标签:ciphertext,int,Programming,plaintext,Caesar,2019,line,include,define 来源: https://www.cnblogs.com/Shallow-dream/p/11440874.html