Files
python/TangDou/LuoGuBook/P1914.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

23 lines
595 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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