Mizuiro79 @ 2021-07-03 14:45:57
#include<bits/stdc++.h>
using namespace std;
int main()
{
char str[60];
int n;
cin>>n;
gets(str);
for(int i=0;i<strlen(str);i++)
{
if(str[i]=='z'&&n>0)
{
str[i]='a';
str[i]+=n-1;
}
else
{
str[i]+=n;
}
}
puts(str);
return 0;
}
by hanyuchen2019 @ 2021-07-03 14:49:44
@江澂子、堯 str
数组没有初始化,并且使用gets()
会炸掉
by Cat_shao @ 2021-07-03 14:50:09
if(str[i]=='z'&&n>0)
{
str[i]='a';
str[i]+=n-1;
}
题面说str[i]+=n-1;
可能会超出a~z
的范围。
by Mizuiro79 @ 2021-07-03 14:50:50
@hanyuchen2019 ok
by Mizuiro79 @ 2021-07-03 14:51:11
@Cat_shao 好的,蟹蟹
by Mizuiro79 @ 2021-07-03 14:52:09
已经做出来了qwq
by Cat_shao @ 2021-07-03 14:53:38
scanf不香吗?
AC代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
char str[60];
int n;
cin>>n;
scanf("%s", str);
for(int i=0;i<strlen(str);i++)
{
str[i] = 'a' + (str[i] - 'a' + n) % 26;
}
puts(str);
return 0;
}
基本没改,核心代码就是for循环里的那个
by Balloonist @ 2021-07-05 22:39:37
考古