Files
python/TangDou/LuoGuBook/P1914.cpp

23 lines
595 B
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
cin >> n >> s;
//遍历每个字符
for (int i = 0; i < s.size(); i++) {
//s[i]遍历到的字符,s[i]+n就是目标字符,但是有可能是超过了'z'的
int c = s[i] + n;
//超过了z,该怎么办呢?
if (c > 'z') c = c - 'z' - 1 + 'a';
// if (c > 'z') c = c - 26;
//重新的放回到原来的数组位置上,生成新的字符串
s[i] = c;
//s[i] = (char) c;
}
cout << s << endl;
return 0;
}