题解 | 凯撒解密
凯撒解密
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;
}
};

查看27道真题和解析