题解 | #MP3光标位置#
MP3光标位置
https://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let total = 0; let input = ""; rl.on("line", function (line: string) { if (total === 0) { total = parseInt(line, 10); } else { input = line; } }); rl.on("close", () => { // 窗口坐标 let x = 0; // 光标坐标 let y = 0; input.split("").forEach((v) => { if (v === "U") { if (y === x) { x -= 1; } y -= 1; } else { if (x + 3 === y) { x += 1; } y += 1; } if (x === -1 || y === -1) { x = total - 1 y = total - 1 } if (x === total || y === total) { x = 0 y = 0 } }); let result = [] const length = Math.min(total, 4) if (x + 3 <= total-1) { result = Array.from( {length}, (v, k) => x + k+1 ) } else { result = Array.from( {length}, (v, k) => total-length+k+1 ) } console.log(result.join(' ')) console.log(y + 1) });