yxq5253 @ 2023-01-09 19:26:52
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
n=n%26;
string str;
cin>>str;
int len=str.size();
for(int i=0;i<len;i++)
{
str[i]+=n;
if(str[i]>'z') str[i]-=26;
}
cout<<str;
return 0;
}
by One_more_light @ 2023-01-09 19:56:36
这里建议先减26再还原
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
n=n%26;
string str;
cin>>str;
int len=str.size();
for(int i=0;i<len;i++)
{
str[i]=str[i]-26+n;
if(str[i]<'a') str[i]+=26;
}
cout<<str;
return 0;
}
by zhuowei123 @ 2023-02-05 23:06:04
@One_more_light 这是什么原理啊
by ai_user @ 2023-02-08 13:28:04
@zhuowei123 看的别的帖子说的好像超出ASCII编码范围会出现错误