jmfovo @ 2023-04-24 21:50:54
#include<iostream>
#include<cstring>
using namespace std;
char a[51];
int main() {
int n;
cin >> n >> a;
int b = strlen(a);
for (int i = 0;i<b; i++) {
a[i] += n;
if (a[i] > 122)
a[i] = a[i] % 122 + 96;
}
cout << a;
}
by liuzikun___ @ 2023-04-24 22:14:17
你学过string类型字符串吗?
可以参考一下我的代码
~~~#include <iostream>
#include <cstring>
using namespace std;
string s;
int n;
int main()
{
int n;
cin >> n >> s;
int size = s.size();
for(int i = 0; i <= size; i++)
{
if(s[i] + n > 'z')
{
s[i] += n - 26;
}
else
{
s[i] += n;
}
}
cout << s << endl;
}
~~~