题解 | #密码翻译#

密码翻译

https://www.nowcoder.com/practice/136de4a719954361a8e9e41c8c4ad855

#include<bits/stdc++.h>
using namespace std;

int main() {
    string str;
    getline(cin, str);//读取输入的字符串
    for (char c : str) {
        //如果字符是小写z,输出小写a
        if (c == 'z') {
            cout << 'a';
        }
        //如果字符是大写Z,输出大写A
        else if (c == 'Z') {
            cout << 'A';
        }
        //如果字符是其他字母,输出其后一个字母
        else if ((c >= 'a' && c <= 'y') || (c >= 'A' && c <= 'Y')) {
            cout << char(c + 1);
        }
        //如果是其他字符,照常输出
        else {
            cout << c;
        }
    }
}

全部评论

相关推荐

求offer的大角牛:不吃香菜
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务