'commit'
This commit is contained in:
23
TangDou/LuoGuBook/P1914.cpp
Normal file
23
TangDou/LuoGuBook/P1914.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user