xinze1 @ 2023-04-08 21:19:05
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main(){
// char st[561];
int n;
cin>>n;
scanf("\n");
char st[51];
fgets(st,51,stdin);
for(int i=0;st[i];i++)
{
st[i]=st[i]+n;
if(st[i]>122){st[i]-=26;}
cout<<st[i];
}
return 0;
}
by Cindy_Li @ 2023-04-08 21:36:00
@xinze1 因为有可能st[i]+n-26>122
,谁说只能循环一次的
by xiezerui @ 2023-04-09 11:38:15
@xinze1
#include <stdio.h>
int main()
{
char in[100];
int n;
int j;
scanf("%d%s", &n, in);
for(j = 0; in[j] != '\0'; j++)
{
putchar((in[j]-'a'+n)%26+'a');
}
return 0;
by xiezerui @ 2023-04-09 11:38:59
这样就可以AC了!!!
by wangjiawen @ 2023-05-02 20:50:08
@Cindy_Li 确实。我就直接加,结果一直WA #5。最后下载样例才知道z(122)+25=147超出了ascll范围