题解 | 凯撒解密

凯撒解密

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

#include <string>
class Solution {
public:
    string decodeWangzai(string password, int n) {
        n = n % 26;
        if(n == 0) return password;
        for(int i = 0; i < password.length();i++){
            password[i] = (password[i] - 'a' - n + 26) % 26 +'a';
		  //用于处理大于26的数,相当于再字母表前面多排了一份字母表,+26回到原字母表。
        }
        return password;
    }
};

全部评论

相关推荐

点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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