chenzhongmugu @ 2024-08-11 15:51:06
#include<bits/stdc++.h>
using namespace std;
int main()
{
char a[60]={0};
int n;
cin>>n>>a;
for(int i=0;a[i];i++)
{
char tmp=a[i];
if(tmp+n>122)
{
cout<<char(tmp+n-122+97-1);
}
else
{
tmp=a[i]+n;
cout<<tmp;
}
}
return 0;
}
by fanyuqi @ 2024-08-15 21:59:13
a是char类型数组不是字符串,你只输入了第一个Σ(⊙▽⊙"a
by fanyuqi @ 2024-08-15 22:00:00
而且你写的是a不是a[]
by yangzijin @ 2024-08-25 22:52:14
@chenzhongmugu 可以这样写:```
using namespace std; int main(){ string s; int n; cin>>n; cin>>s; for(int i=0;i<s.size();i++){ s[i]==int(s[i]-'a'+n)%26+'a'; } cout<<s; return 0; }
AC代码