题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
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 const tab = { '0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, 'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15, }; while(line = await readline()){ if (line.startsWith('0x') && line.length > 2) { let tokens = line.split(''); let sum = 0; for (let i = tokens.length - 1, j = 0; i > 1; i--, j++) { sum += tab[tokens[i]] * Math.pow(16, j); } console.log(sum); } } }()