题解 | 凯撒解密

凯撒解密

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

class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 进行凯撒解密
     * @param password string字符串 旺仔哥哥的密码
     * @param n int整型 每个字符加密过程中错位的次数
     * @return string字符串
     */
     // 字符串中字符向前移位N次 s[i]=(s[i]-'a'-n)>=0+'a', <0,26 -s[i]+'a';
    string decodeWangzai(string password, int n) {
        // write code here
        n%=26;
        for (int i = 0 ; i < password.length(); i++){
                if(password[i] - 'a' -n >= 0) password[i] = password[i] -n;
                else password[i] = 26 + (password[i] -'a'-n)+'a';//先计算偏移量再还原
              
        }
         return password;
    }
};

全部评论

相关推荐

烤点老白薯:感觉这女生 有上位者的甲方心态 不适合处对象 也不清楚自己的竞争力 整得他有多懂似的
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

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