字母变换 前推以及后推
作者:
WindSkyEnd
,
2024-11-10 09:38:48
,
所有人可见
,
阅读 2
常规做法
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long int;
int main()
{
string str;
getline(cin,str);
for(char &a : str)
{
if(a<'Z'&& a>='A') a = (a+1)%65;
else if(a=='Z') a = 'A';
else if(a<='z'&&a>'a') a = a-1;
else if(a =='a') a = 'z';
}
cout << str;
return 0;
}
ch = 'A' + (ch-'A'+1)%26; 后推
ch = 'z' - ('z'-ch+1)%26; 前推
//规律就是 去掉%26 后 是+1就后推 是-1就前推 然后再加上取模