题目内容:在情报传递过程中,为了防止情报被截获,往往需要对情报用一定的方式加密,简单的加密算法虽然不足以完全避免情报被破译,但仍然能防止情报被轻易的识别。我们给出一种最简的的加密方法,对给定的一个字符串,把其中从a-y,A-Y的字母用其后继字母替代,把z和Z用a和A替代,则可得到一个简单的加密字符串。
输入格式:
第一行是字符串的数目n。
其余n行每行一个字符串。
输出格式:
输出每行字符串的加密字符串。
输入样例:
1 Hello! How are you!
输出样例:
Ifmmp! Ipx bsf zpv!
#include <iostream>
#include<cstdio>
#include<algorithm>
#include <cstring>
#include<stack>
#include <string>
#include<math.h>
#define MAX 210
using namespace std;
int main(int argc, char const *argv[])
{ int n;
cin>>n;
cin.get();
string str[n];
int i=0;
int n2=n;
while(n2--){
getline(cin,str[i++]);
}
for (int i = 0; i < n; ++i)
{ int count=str[i].size();
for (int j = 0; j < count; ++j)
{
if(str[i][j]=='z')str[i][j]='a';
else if (str[i][j]=='Z')str[i][j]='A';
else if ((str[i][j]>='a'&&str[i][j]<='y')||(str[i][j]>='A'&&str[i][j]<='Y'))
str[i][j]=str[i][j]+1;
}
}
for (int i = 0; i < n; ++i)
{
cout<<str[i]<<endl;
}
return 0;
}