蓝桥杯 ADV-225 算法提高 9-2 文本加密

问题描述
先编写函数EncryptChar,按照下述规则将给定的字符c转化(加密)为新的字符:"A"转化"B","B"转化为"C",... ..."Z"转化为"a","a"转化为"b",... ..., "z"转化为"A",其它字符不加密。编写程序,加密给定字符串。
样例输出
与上面的样例输入对应的输出。
例:

数据规模和约定
输入数据中每一个数的范围。
例:50个字符以内无空格字符串。

#include <iostream>
#include <algorithm>
#include <vector>
#include <cctype>
#include <map>
using namespace std;
string encrypt(string s) {
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'Z') s[i] = 'a';
        else if (s[i] == 'z') s[i] = 'A';
        else if (isalpha(s[i])) s[i]++;
    }
    return s;
}
int main() {
    string s;
    cin >> s;
    cout << encrypt(s);
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值