XMDxmd0525 @ 2022-03-19 14:36:44
为什么会错,大佬救救我
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
char a[101], i=0, n;
int main(){
cin>>n;
while((a[i]=getchar())!='\n') i++;
a[i]='\0';
if(n>26) n=n%26;
for(int j=0;j<i;j++){
a[j]=(a[j]-'a'+n)%26+'a';
}
for(i=0;a[i]!='\0';i++) putchar(a[i]);
}
by YDMaYi @ 2022-03-19 14:56:00
@XMDxmd0525
洛谷测评姬用getchar()会死掉
by XMDxmd0525 @ 2022-03-19 14:58:14
@hard_fang 可是上一题我用getchar()没有错
by YDMaYi @ 2022-03-19 15:02:32
@XMDxmd0525
还有i是int类型的
by XMDxmd0525 @ 2022-03-19 15:12:07
@hard_fang 这个后来我改了还是错,呜呜呜
by YDMaYi @ 2022-03-19 15:17:37
@XMDxmd0525
n也是
by XMDxmd0525 @ 2022-03-19 15:18:54
这样改了还是错的
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
char a[101];
int i=0, n, j;
int main(){
cin>>n;
while((a[i]=getchar())!='\n') i++;
a[i]='\0';
if(n>26) n=n%26;
for(j=0;j<i;j++){
a[j]=(a[j]-'a'+n)%26+('a');
}
for(i=0;a[i]!='\0';i++) putchar(a[i]);
}
@hard_fang
by YDMaYi @ 2022-03-19 15:20:45
字符串末尾是‘\0’
while((a[i]=getchar())!='\n') i++;
应改成
while((a[i]=getchar())!='\0') i++;
by YDMaYi @ 2022-03-19 15:24:37
@XMDxmd0525
by ben090302 @ 2022-03-19 15:36:12
@XMDxmd0525 抱歉,你的我改了半天改不对所以我把我的给你康康
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,lens;
char s[60];
scanf("%d\n%s",&n,s);//输入
lens=strlen(s)-1;//长度
for(int i=0;i<=lens;i++){
if(s[i]+n>'z') s[i]=(s[i]-'a'+n)%26+'a';//如果超过z
else s[i]=s[i]+n;//没超过
}
puts(s);//puts直接输出整串
return 0;
}
by XMDxmd0525 @ 2022-03-19 20:43:44
@ben090302 没事哈,谢谢你