rabbit_Cicy @ 2024-09-21 15:33:46
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
char c[51];
cin>>n;
for(int i=1; i<=50; i++){
cin>>c[i];
putchar(char((c[i]-'a'+n)%26+'a'));
}
return 0;
}
by elseif123 @ 2024-09-21 15:45:20
首先定一个字符串或是一个容量大一点点的char类型数组,然后使用for逐个的将字符转换为ascll码值,并在码值的基础上+n再重新转化为char(or string)类型的字符就可以啦。
by qiaochu @ 2024-09-21 15:47:04
@rabbit_Cicy
#include<bits/stdc++.h>
using namespace std;
int main()
{
char a[200];
int n,l;
cin>>n>>a;
for(int i=0;i<strlen(a);i++)
{
l=a[i]-96+n;
while(l>26)l-=26;
cout<<char(l+96);
}
return 0;
}
by rabbit_Cicy @ 2024-09-21 16:32:40
@qiaochu 除了#5,其他全红了
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, a;
char c[200];
scanf("%d %s", &n, c);
for(int i=0; i<=strlen(c); i++){
a=c[i]-96+n;
while(a>26) a-=26;
cout<<char(a+96);
}
return 0;
}
by qiaochu @ 2024-09-21 16:48:12
@rabbit_Cicy 我这个代码应该能A啊
ACcode
by rabbit_Cicy @ 2024-09-21 16:58:13
@qiaochu
WA code
by qiaochu @ 2024-09-21 19:39:50
@rabbit_Cicy
7行i<=strlen(c)改成i<strlen(c)试试
by Hzk119 @ 2024-10-26 20:34:01
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
char s[55];
cin>>n>>s;
for(int i=0;s[i]!='\0';++i)
{
for(int j=0;j<n;++j)
{
if(s[i]=='z')
s[i]='a';
else
s[i]++;
}
}
cout<<s;
return 0;
}