MornHus @ 2022-08-29 16:40:59
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
char a;
while(cin>>a){
a+=n;
if(a>'z')a%=26;
cout<<a;
}
return 0;
}
by bamboo12345 @ 2022-08-29 16:44:40
@zjybb 如果n很大的话,你想想char的最大上限是127,那么一加不就炸了?
by int9 @ 2022-08-29 16:46:00
@zjybb 你确定可以直接取模???
by bamboo12345 @ 2022-08-29 16:46:59
@zjybb 而且'z'的ASCII码值可是一百多,你觉得你该对26取模吗
by MornHus @ 2022-08-29 16:49:49
@bamboo123
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
n%=26;
char a;
while(cin>>a){
a+=n;
if(a>'z'){a%=26;a+='a';}
cout<<a;
}
return 0;
}
已修改,只有80分,第四个wa
by bamboo12345 @ 2022-08-29 16:51:27
@zjybb 你要先用int判断会不会加炸再去修改,先减去26再加上n
by leoqing @ 2022-08-29 16:51:34
求关注
#include <bits/stdc++.h>
using namespace std;
int main(){
char a[300] ;
int i,n,x,b[300];
cin>>n>>a;
x=strlen(a);
for (i=0;i<x;i++)b[i]=a[i];
for (i=0;i<x;i++)b[i]=b[i]+n;
for (i=0;i<x;i++){
if (b[i]>122)b[i]=b[i]%122+96;
}
for(i=0;i<x;i++){
a[i]=b[i];
cout<<a[i];
}
}
by myyyIisq2R @ 2022-08-29 16:53:26
@zjybb
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
char a;
while (cin >> a)
{
int t = n % 26;
t += a - 'a';
t %= 26;
cout << (char)('a' + t);
}
return 0;
}
by myyyIisq2R @ 2022-08-29 16:53:49
AC代码
by myyyIisq2R @ 2022-08-29 16:55:27
@zjybb 我很早写的一个循环暴力。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n{};
string s;
cin >> n >> s;
for (int i{}; i < s.size(); i++)
{
for (int j{}; j < n; j++)
{
s[i]++;
if (s[i] > 'z')
s[i] = 'a';
}
}
cout << s;
}
by int9 @ 2022-08-29 17:46:31
@zjybb 你的代码逻辑问题很大啊。。。if(a>'z'){a%=26;a+='a';}
应该改成 if(a>'z'){a-='z',a%=26;a+='a';}
懒得测,你自己试试吧