shangyuang @ 2023-07-14 21:25:04
#include<bits/stdc++.h>
using namespace std;
int n,i,j,k,len;
string s;
char huan(char a){
while(a>'z'){
a=char(a-'z'+'a'-1);
}
return a;
}
int main(){
scanf("%d",&n);
cin>>s;
len=s.length();
for(i=0;i<len;++i){
s[i]=huan(s[i]+n);
}
cout<<s;
return 0;
}
#3#4 WA
by Slient_QwQ @ 2023-07-14 21:35:48
#include<bits/stdc++.h>
using namespace std;
int n,i,j,k,len;
char s[114514];
int main(){
scanf("%d",&n);
cin>>s;
len=strlen(s);
for(i=0;i<len;++i){
for(j=1;j<=n;j++)//必须得用for,不知道为什么直接减过不了
{
s[i]++;
if(s[i]>'z')s[i]-=26;
}
}
cout<<s;
return 0;
}
by ccf_0102 @ 2023-07-15 18:15:20
@shangyuang z的ASCII值很大,再加就爆成负数了
by shangyuang @ 2023-07-15 18:16:18
@ccf_0102 怎么解决呢
by ccf_0102 @ 2023-07-15 18:17:26
@shangyuang 可以像一楼一样,或者判断条件改成a不在'a'-'z'之间
by shangyuang @ 2023-07-15 18:18:51
@ccf_0102 哦,我试试
by shangyuang @ 2023-07-15 18:22:14
@ccf_0102 ac了,谢谢喵
by ccf_0102 @ 2023-07-15 18:23:03
@shangyuang 特地把关于关注我的内容删了然后重发是吧(
by shangyuang @ 2023-07-15 18:24:28
@ccf_0102 但我还是关注你了喵
by ccf_0102 @ 2023-07-15 18:25:30
@shangyuang 是这样的喵
by shangyuang @ 2023-07-15 18:28:24
@ccf_0102 能给我一个关注吗喵