zoukankan      html  css  js  c++  java
  • TOJ3070. Encryption

    3070.   Encryption
    Time Limit: 1.0 Seconds   Memory Limit: 65536K
    Total Runs: 1960   Accepted Runs: 903



    You must have heard of an ancient encryption called Caesar cipher or 'shift cipher'. That is, given the plaintext and a number D, you should replace every character c in the plaintext with another character which is D places after c in the alphabet. For example, if D= 2, you should replace 'a' with 'c', replace 'b' with 'd', ... replace 'y' with 'a', and replace 'z' with 'b'.

    Given the plaintext and D, you should output the cipher text.

    Input

    The first line is an integer T, the number of test cases. Then Tcases follows.

    Each case contains only one line, consists of the plaintext and the number D, separated by a space. You can assume there are only lower case letters in the plaintext, and the length is no more than 100. 0 ≤ D < 26.

    Output

    Output one line for each test case, indicating the cipher text.

    Sample Input

    2
    tjucs 1
    abcd 0
    

    Sample Output

    ukvdt
    abcd
    View Code
    #include<iostream>
    using namespace std;
    #include<string.h>
    #include<stdio.h>
    char str[110];
    int shu[110];
    int main()
    {
        int n,i,len,m;
        cin>>n;
        getchar();
        while(n--)
        {
        memset(str,'0',sizeof(str));
          cin>>str;
          cin>>m;
          len=strlen(str);
          for(i=0;i<len;i++)
          {
          
            shu[i]=str[i]-'a';
            printf("shu[%d]=%d\n",i,shu[i]);
          }
           for(i=0;i<len;i++)
           {
              if(shu[i]+m>=26)
              shu[i]+=m-26;
              else
              shu[i]=shu[i]+m;
            }
           for(i=0;i<len;i++)
             printf("%c",shu[i]+'a');
             printf("\n");
        }
        return 0;
    }
           
        
  • 相关阅读:
    docker
    SAML(Security assertion markUp language) 安全断言标记语言
    kafka消息系统
    OBS 对象存储技术学习
    AOP之AspectJ
    sql查漏补缺
    todolist
    springboot 注解整理
    前端之jQuery
    前端之BOM和DOM
  • 原文地址:https://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_2012_08_010000.html
Copyright © 2011-2022 走看看