caikun @ 2022-10-18 21:42:52
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char s[50];
int n;
cin >> n;
n = n % 26;
cin >> s;
for (int i = 0; i < strlen(s); i++)
{
while (s[i] + n > 'z')
{
s[i] = s[i] + n - 26;
}
s[i] = s[i] + n;
}
cout << s;
return 0;
}
by qiuqiuqzm @ 2022-10-18 22:24:53
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char s[50];
int n;
cin >> n;
n = n % 26;
cin >> s;
for (int i = 0; i < strlen(s); i++)
{
if (s[i] + n > 'z')
{
s[i] = s[i] + n - 26;
}
else
s[i] = s[i] + n;
}
cout << s;
return 0;
}
改好了,要用if+else,不然大于'z'时会多加一次
by jjy2008 @ 2022-10-18 22:27:42
#include<bits/stdc++.h>
using namespace std;
int main()
{
char s[50];
int n;
cin >> n;
n = n % 26;
cin >> s;
for (int i = 0; i < strlen(s); i++)
{if((s[i] + n > 'z'))
s[i] = s[i] + n - 26;
else
s[i] = s[i] + n;
}
cout << s;
return 0;
}
by jjy2008 @ 2022-10-18 22:28:31
@qiuqiuqzm
慢了一步
by qiuqiuqzm @ 2022-10-20 21:36:31
@jjy2008 hh