zoukankan      html  css  js  c++  java
  • UVALive 5880 Vigenère Cipher Encryption (模拟)

    Stack Machine Executor

    题目链接:

    http://acm.hust.edu.cn/vjudge/problem/26628

    Description

    http://7xjob4.com1.z0.glb.clouddn.com/18113a5cf78f108997460e36f7079fc6

    Input

    The input contains several instances. Each instance consists of two lines, the first line is the encryption key and the second line is the plaintext. Both key and plaintext consist of uppercase letters of the English alphabet {A, B, C, . . . , Z}. The length of the key will be between 1 and 1000, the length of the plaintext between 1 and 100 000, inclusive. Input is terminated by a line containing one zero.

    Output

    For each input instance, output the ciphertext — the encrypted version of the message.

    Sample Input

    ICPC THISISSECRETMESSAGE ACM CENTRALEUROPEPROGRAMMINGCONTEST LONGKEY CERC 0

    Sample Output

    CKYVRVIHLUUWVHIVJJU DHAUUNMHHSRCFSEPJEBPZJQTDRAUHFU OTFJ

    Source

    2016-HUST-线下组队赛-1
    ##题意: 用密钥来加密字符串.
    ##题解: 题目真是长,然而是签到题... 要练习一下快速读题了...不要看到长题面不敢读.. 直接模拟即可.
    ##代码: ``` cpp #include #include #include #include #include #include #include #include #include #include #include #define LL long long #define eps 1e-8 #define maxn 101000 #define mod 100000007 #define inf 0x3f3f3f3f #define mid(a,b) ((a+b)>>1) #define IN freopen("in.txt","r",stdin); using namespace std;

    char str[maxn];
    char key[maxn];

    int main(int argc, char const *argv[])
    {
    //IN;

    while(gets(key) && key[0] != '0')
    {
        gets(str);
    
        int klen = strlen(key);
        int len = strlen(str);
    
        for(int i=0,j=0; i<len; i++,j++) {
            if(j == klen) j = 0;
            str[i] = (str[i] + key[j] - 'A' + 1 - 'A') % 26 + 'A';
        }
    
        puts(str);
    }
    
    return 0;
    

    }

  • 相关阅读:
    维护
    zabbix监控线
    java——快排、冒泡、希尔、归并
    java——注解处理器
    spring boot——常用注解
    java——修改txt文件中某一行的内容
    spring boot——关于一个Mysql主键的问题
    mysql
    springboot
    自信点,不要怕
  • 原文地址:https://www.cnblogs.com/Sunshine-tcf/p/5791209.html
Copyright © 2011-2022 走看看