JulieWei @ 2024-04-22 09:50:34
拿错了 嘤嘤嘤
#include<bits/stdc++.h>
using namespace std;
int a,ans;
string s,b;
int main(){
cin>>a;
cin>>s;
for(int i=0;i<=s.size();i++){
ans=s[i]+a;
if(ans==122) ans-=25;
b[i]=ans;
cout<<b[i];
}
}
by llamn @ 2024-04-22 11:19:23
@JulieWei
i<=s.size()
改为 i < s.size()
by JulieWei @ 2024-04-22 11:42:11
@20100916cyy_ 还是有2个wa,一个re, 但感谢!
by Ray1029 @ 2024-04-22 20:54:38
@JulieWei 可以改一改为
#include<bits/stdc++.h>
using namespace std;
int main() {
int a;
char s[60];
cin >> a ;
cin >> s;
for(int i = 0 ; s[i] != '\0' ; i++){
if (s[i] + a <= 'z'){
s[i] = s[i] + a;
}
else s[i] = s[i] + a - 26;;
}
cout << s;
return 0;
}
这是AC的,可以试着理解一下
by malinhao45 @ 2024-04-25 21:03:12
#include<bits/stdc++.h>
using namespace std;
int a,ans;
string s,b;
int main(){
cin>>a;
cin>>s;
for(int i=0;i<s.size();i++){
ans=s[i]+a;
if(ans>122){
ans%=122;
ans+=96;
}
b[i]=ans;
cout<<b[i];
}
}
by malinhao45 @ 2024-04-25 21:03:59
AC
by malinhao45 @ 2024-04-25 21:04:39
记得关o2