Constantine____ @ 2024-12-06 18:48:30
#include<bits/stdc++.h>
using namespace std;
string a;
int main()
{
int n;
cin>>n;
cin>>a;
for(int i=0 ; i<=a.size()-1 ; i++)
{
a[i]+=n;
if(a[i]>122) a[i]-=26;
}
for(int i=0 ; i<=a.size()-1 ; i++)
{
cout<<a[i];
}
}
by xiezt123456 @ 2024-12-06 19:10:36
@Constantine____
#include <iostream>
using namespace std;
string a;
int main() {
int n;
cin >> n;
cin >> a;
for (int i = 0; i < a.size(); i++) {
if (isalpha(a[i])) { // 检查是否为字母
char base = islower(a[i]) ? 'a' : 'A'; // 判断是小写还是大写字母
a[i] = (a[i] - base + n) % 26; // 计算新的字符位置
if (a[i] < 0) a[i] += 26; // 处理负数情况
a[i] += base; // 转换回字符
}
}
cout << a;
return 0;
}
求关
by Constantine____ @ 2024-12-06 22:53:21
@xiezt123456 已回关,感谢