题解 | 凯撒解密

凯撒解密

https://www.nowcoder.com/practice/42c2f0c1351e4a6689ff64eddaf97a37

class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 进行凯撒解密
     * @param password string字符串 旺仔哥哥的密码
     * @param n int整型 每个字符加密过程中错位的次数
     * @return string字符串
     */
    string decodeWangzai(string password, int n) {
        int a,b;
        for(int i=0;i<password.size();i++){
            a=password[i]%97;
            n=n%26;
            b=a-n;
            if (b>=0) {
            password[i]=97+b;
            }
            if (b<0) {
            password[i]=123+b;
            }
        }
        return password;
    }
};

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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