扩大
缩小

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

 

posted on 2012-08-02 16:14  LinuxPanda  阅读(229)  评论(0编辑  收藏  举报

导航