zoukankan      html  css  js  c++  java
  • 2018 ACM-ICPC 宁夏 C.Caesar Cipher(模拟)

    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 19, A would be replaced by T, B would be replaced by U, and so on.A full exhaustive list is as follows:

     

    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.

    Input Format

    The input contains several test cases, and the first line is a positive integer T indicating the number of test cases which is up to 50.

    For each test case, the first line contains two integers nn and m~(1 le n,m le 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 n, indicating a given plaintext and its ciphertext respectively.The fourth line gives another ciphertext only with capital letters of length m.

    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.

    Output Format

    For each test case, output a line containing Case #x: T, where x is the test case number starting from 1, and T is the plaintext of the ciphertext given in the fourth line.

    样例输入

    1
    7 7
    ACMICPC
    CEOKERE
    PKPIZKC

    样例输出

    Case #1: NINGXIA

    挺简单的一道题,刚开始竟然wa了。。。太菜了

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <iostream>
     4 #include <string>
     5 #include <math.h>
     6 #include <algorithm>
     7 #include <vector>
     8 #include <queue>
     9 #include <set>
    10 #include <stack>
    11 #include <map>
    12 #include <math.h>
    13 const int INF=0x3f3f3f3f;
    14 typedef long long LL;
    15 const int mod=1e9+7;
    16 const int maxn=1e5+10;
    17 using namespace std;
    18 //ios::sync_with_stdio(false);
    19 //    cin.tie(NULL);
    20 
    21 int main()
    22 {
    23     int T;
    24     cin>>T;
    25     for(int k=1;k<=T;k++)
    26     {
    27         int n,m;
    28         cin>>n>>m;
    29         string s1,s2,s3;
    30         cin>>s1>>s2;
    31         int p=s1[0]-s2[0];
    32         cin>>s3;
    33         cout<<"Case #"<<k<<": ";
    34         for(int i=0;i<m;i++)
    35         {
    36             cout << char((s3[i]-'A'+p +26)%26 + 65);    
    37         }
    38         cout<<endl;
    39     }
    40     return 0;
    41 }
  • 相关阅读:
    杜教筛学习笔记
    Dirichlet 卷积学习笔记
    洛谷 [POI2007]BIU-Offices 解题报告
    NOIP 2018 游记
    洛谷 P4964 绫小路的特别考试 解题报告
    洛谷 P4597 序列sequence 解题报告
    洛谷 P2757 [国家集训队]等差子序列 解题报告
    对答案 解题报告
    multimap-find
    multimap-insert
  • 原文地址:https://www.cnblogs.com/jiamian/p/11438773.html
Copyright © 2011-2022 走看看