早教吧 育儿知识 作业答案 考试题库 百科 知识分享

一道很简单的ACM题,求大神看看我错在哪儿了,C++YoumusthaveheardofanancientencryptioncalledCaesarcipheror'shiftcipher'.Thatis,giventheplaintextandanumberD,youshouldreplaceeverycharactercintheplaintextwithan

题目详情
一道很简单的ACM题,求大神看看我错在哪儿了,C++
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.
InputThe first line is an integer T,the number of test cases.Then T cases 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.
OutputOutput one line for each test case,indicating the cipher text.
Sample Input2
tjucs 1
abcd 0
Sample Outputukvdt
abcd
我的代码:
#include
#include
using namespace std;
int main()
{
int a,i,n;
char s[99];
while(cin>>a)
{
for(i=0;i>s>>n;
int l=strlen(s);
for(int j=0;j
▼优质解答
答案和解析
#include
#include
using namespace std;
int main()
{
int a,i,n;
char s[111]; //这里可以开大一点,因为结尾还有一个字符是'\0';
while(cin>>a)
{
for(i=0;i>s>>n;
int l=strlen(s);
for(int j=0;j'z') //这里还可能超出字母的范围
k-=26;
cout
看了 一道很简单的ACM题,求大神...的网友还看了以下: