题解 | 凯撒解密
凯撒解密
https://www.nowcoder.com/practice/42c2f0c1351e4a6689ff64eddaf97a37
class Solution {
public:
string decodeWangzai(string password, int n) {
for(int i=0; i<password.size(); i++) {
int offset = n % 26; // 处理n大于26的情况
if(password[i] - offset < 'a') {
password[i] = 'z' - (offset - (password[i] - 'a') - 1);
} else {
password[i] = password[i] - offset;
}
}
return password;
}
};

查看1道真题和解析