题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1048
题目大意:对一串字符串进行加密:每个英文字母变为字母表此后第五位,其他字符无变化。给出密码,要求翻译为原串。
关键思想:字符串处理
代码如下:
//字符串处理。边界搞好
#include <iostream>
using namespace std;
int main(){
string temp;
while(cin>>temp){
if(temp=="ENDOFINPUT")break;
if(temp=="START"){
getchar();//吃掉回车
getline(cin,temp);
for(int i=0;i<temp.size();i++){
if(temp[i]>='A'&&temp[i]<='E')
temp[i]+=21;
else if(temp[i]>'E'&&temp[i]<='Z')
temp[i]-=5;
}
cout<<temp<<endl;
cin>>temp;
}
}
return 0;
}