华为-字符串加解密
题目链接
#include using namespace std;void Encrypt (string s, string &a){ for (int i = 0; i < s.length(); ++i){ if (s[i] >= 'a' && s[i] < 'z'){ a[i] = s[i] - 31; } else if (s[i] == 'z'){ a[i] = 'A'; } if (s[i] >= 'A' && s[i] < 'Z'){ a[i] = s[i] + 33; } else if (s[i] == 'Z'){ a[i] = 'a'; } if (s[i] >= '0' && s[i] < '9'){ a[i] = s[i] + 1; } else if (s[i] == '9'){ a[i] = '0'; } }}void unEncrypt (string s, string &a){ for (int i = 0; i < s.length(); ++i){ if (s[i] > 'a' && s[i] <= 'z'){ a[i] = s[i] - 33; } else if (s[i] == 'a'){ a[i] = 'Z'; } if (s[i] > 'A' && s[i] <= 'Z'){ a[i] = s[i] + 31; } else if (s[i] == 'A'){ a[i] = 'z'; } if (s[i] > '0' && s[i] <= '9'){ a[i] = s[i] - 1; } else if (s[i] == '0'){ a[i] = '9'; } }}int main(){ string a, b, c, d; while (cin >> a) { cin >> b; c = a; d = b; Encrypt(a, c); unEncrypt(b, d); cout << c << endl << d << endl; } return 0;}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~