小书童——凯撒密码
题目背景
某蒟蒻迷上了 “小书童”,有一天登陆时忘记密码了(他没绑定邮箱 or 手机),于是便把问题抛给了神犇你。
题目描述
蒟蒻虽然忘记密码,但他还记得密码是由一个字符串组成。密码是由原文字符串(由不超过 50 个小写字母组成)中每个字母向后移动
n
n
n 位形成的。z
的下一个字母是 a
,如此循环。他现在找到了移动前的原文字符串及
n
n
n,请你求出密码。
输入格式
第一行: n n n。第二行:未移动前的一串字母。
输出格式
一行,是此蒟蒻的密码。
样例 #1
样例输入 #1
1
qwe
样例输出 #1
rxf
提示
字符串长度 ≤ 50 \le 50 ≤50。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
using namespace std;
int main(){
int n;
cin>>n;
string s;
cin>>s;
for(int i = 0; i < s.length(); i++){
if(s[i] + n > 'z'){
s[i] = s[i] + n - 26;
}else{
s[i] = s[i] + n;
}
}
cout<<s;
return 0;
}