mitochondria @ 2024-01-03 20:47:36
#include <stdio.h>
int main()
{
int j,m,n,x,i,t;
char a[50]={0},b[50]={0};
scanf("%d%s",&n,a);
while(n>=26)
n%=26;
for(i=0;a[i]!='\0';i++)
{
j++;
}
for(i=0;i<j;i++)
{
b[i]=a[i]+n;
}
for(i=0;i<j;i++)
{
if(b[i]>'z')
{
b[i]='a'+n-1-('z'-a[i]);
}
}
for(i=0;i<j;i++)
{
printf("%c",b[i]);
}
return 0;
}
by GXZJQ @ 2024-01-03 20:54:54
@mitochondria 万一超出范围了呢?
by GXZJQ @ 2024-01-03 20:55:43
@mitochondria
#include<bits/stdc++.h>
using namespace std;
int n;
string zimu;
int main() {
cin>>n;
cin>>zimu;
for(int i=0;i<zimu.size();i++){
putchar((zimu[i]-'a'+n)%26+'a');
}
return 0;
}