密码翻译

题目描述
在情报传递过程中,为了防止情报被截获,往往需要对情报用一定的方式加密,简单的加密算法虽然不足以完全避免情报被破译,但仍然能防止情报被轻易的识别。我们给出一种最简的的加密方法,对给定的一个字符串,把其中从a-y,A-Y的字母用其后继字母替代,把z和Z用a和A替代,则可得到一个简单的加密字符串。
输入描述:
读取这一行字符串,每个字符串长度小于80个字符
输出描述:
对于每组数据,输出每行字符串的加密字符串。
示例1
输入
1 //题目编译有问题,不输入1也对
Hello! How are you!
输出
Ifmmp! Ipx bsf zpv!

题目解析:主要是带空格的字符串的输入,使用getline(cin,str),但是getline的读取是\n为结束的字符串,所以在getline前使用了cin时,要使用cin.ignore();忽略这个\n。

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<map>
#include<vector>

using namespace std;

string handle(string password){
	string newpassword;
	for(int i = 0 ; i < password.size(); i++){
		if(password[i] >='a' && password[i] < 'z'){
			newpassword += (password[i] + 1);
		}else if(password[i] >= 'A' && password[i] < 'Z'){
			newpassword += (password[i] + 1);
		}else if(password[i] == 'z'){
			newpassword += 'a';
		}else if(password[i] == 'Z'){
			newpassword += 'A';
		}else{
			newpassword += password[i];
		}
	}
	return newpassword;
}
int main()
{
    int count;
    string password;
    while(getline(cin , password)){
    	cout << handle(password) << endl;
	}
    /*  前方有数字 
    while(cin >> count){
    	cin.ignore();
    	for(int i = 0 ; i < count ;i ++){
    		getline(cin , password);
    		cout << handle(password) << endl;
		}
	}
	*/
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值