ywx1228 @ 2022-08-05 16:51:26
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,x[55]={0};
cin>>n;
char a[55];
cin>>a;
int num=strlen(a);
for(int i=0;i<num;i++)
{
x[i]=a[i];
int y='z';
x[i]+=n;
while(x[i]>'z')
{
x[i]-=25;
}
a[i]=x[i];
}
for(int i=0;i<num;i++)
{
cout<<a[i];
}
return 0;
}
by xutongwei @ 2022-08-05 16:54:52
@ywx1228 应该是 x[i] -= 26;
……
by __er @ 2022-08-05 17:15:17
@xutongwei 应该是x[i]='a';
……
by ywx1228 @ 2022-08-05 17:18:06
@xutongwei 哦哦好的谢谢
by ywx1228 @ 2022-08-05 17:21:13
@__er 您是说x[i]=a[i]吗?那个应该没有错吧(毕竟是转换,x[i]='a'不就把x[i]直接变成a了哎)(还是谢谢了)
by __er @ 2022-08-05 17:24:42
@ywx1228 抱歉思路不一样……
我是这么写的(远古时期的代码十分lj)
for (i = 0; i < a.length(); i++) {
for (j = 1; j <= n; j++) {
a[i]++;
if (a[i] > 'z') {
a[i] = 'a';
}
}
}
思维复杂度极低,时间复杂度极高……
by ywx1228 @ 2022-08-05 17:30:41
哦哦还是谢谢!