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;
}
       
    

 

转载于:https://www.cnblogs.com/zhaojiedi1992/archive/2012/08/02/zhaojiedi_2012_08_010000.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值