题目内容:在情报传递过程中,为了防止情报被截获,往往需要对情报用一定的方式加密,简单的加密算法虽然不足以完全避免情报被破译,但仍然能防止情报被轻易的识别。我们给出一种最简的的加密方法,对给定的一个字符串,把其中从a-y,A-Y的字母用其后继字母替代,把z和Z用a和A替代,则可得到一个简单的加密字符串。
输入格式:
第一行是字符串的数目n。
其余n行每行一个字符串。
输出格式:
输出每行字符串的加密字符串。
输入样例:
1 Hello! How are you!
输出样例:
Ifmmp! Ipx bsf zpv!
1 #include <iostream>
2 #include <cstring>
3 using namespace std;
4 int main(){
5 int n;
6 string str;
7 cin >> n;
8 cin.get();
9 for (int i = 0; i < n; ++i){
10 getline(cin, str);
11 for (int j = 0; j < str.length(); ++j){
12 if ((str[j] < 'z' && str[j] >= 'a') || str[j] < 'Z' && str[j] >= 'A')
13 str[j] += 1;
14 else if (str[j] == 'z')
15 str[j] = 'a';
16 else if (str[j] == 'Z')
17 str[j] = 'A';
18 }
19 cout << str << endl;
20 }
21 return 0;
22 }