题解 | 简单密码
简单密码
https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
/**
* 简单密码
*/
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void (async function () {
// Write your code here
while ((line = await readline())) {
const strs = line.split("");
const result = [];
const keyboardMap = {
abc: "2",
def: "3",
ghi: "4",
jkl: "5",
mno: "6",
pqrs: "7",
tuv: "8",
wxyz: "9",
};
for (let i = 0; i < strs.length; i++) {
const str = strs[i];
const strCode = str.charCodeAt();
if (!isNaN(Number(str))) {
result.push(str);
} else if (strCode >= 65 && strCode <= 90) {
// 大写
// 先转换为小写
const strLower = str.toLowerCase();
// 找出小写字母的ascii码
if (strCode == 90) {
result.push("a");
} else {
result.push(String.fromCharCode(strLower.charCodeAt() + 1));
}
} else if (strCode >= 97 && strCode <= 122) {
// 小写
Object.keys(keyboardMap).forEach((key) => {
if (key.includes(str)) {
result.push(keyboardMap[key]);
}
});
}
}
console.log(result.join(""));
}
})();
#华为算法题##js解法##算法题##华为OD流程#