yuese0147 @ 2023-07-20 15:14:16
#include<stdio.h>
#include<string.h>
int main (){
char a[60];
int n;
scanf("%d",&n);
getchar();
fgets(a, sizeof(a), stdin);
int length = strlen(a)-1;
for(int i=0;i<length;i++){
a[i] = (char)(((a[i] - 'a' + n) % 26) + 'a');
}
printf("%s",a);
return 0;
}
by l_615 @ 2023-07-20 15:25:12
那个length不用减一,因为你的i已经是小于他了而不是小于等于,代码见下
#include<stdio.h>
#include<string.h>
int main (){
char a[60];
int n;
scanf("%d",&n);
scanf("%s",a);
int length = strlen(a);
for(int i=0;i<length;i++){
a[i]=(char)(((a[i]-'a'+n)%26)+'a');
}
printf("%s",a);
return 0;
}
给个关注吧
by wyl123ly @ 2023-07-20 15:28:19
#include<bits/stdc++.h>
using namespace std;
int fin;
int main(){
string code;
int n;
int move;
char a;
cin>>n;
cin>>code;
int len=code.length();
for(int i=0;i<len;i++){
move=int(code[i]);
for(int i=1;i<=n;i++){
move++;
if(move>122){
move=move-26;
}
}
cout<<char(move);
}
return 0;
}
awa