题解 | #MP3光标位置#
MP3光标位置
https://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
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 total = parseInt(await readline()); const steps = (await readline()).split(""); let currentSelect = 1; let ps = 1; let pageSize = total <= 4 ? total : 4; let pe = pageSize; for (const step of steps) { if (currentSelect === ps && step === "U" && ps === 1) { pe = total; ps = total - pageSize + 1; currentSelect = total; } else if (currentSelect === pe && step === "D" && pe === total) { ps = 1; pe = ps + pageSize - 1; currentSelect = 1; } else if (step === "U" && currentSelect === ps) { ps--; pe--; currentSelect = ps; } else if (step === "D" && currentSelect === pe) { ps++; pe++; currentSelect = pe; } else if (step === "U") { currentSelect--; } else if (step === "D") { currentSelect++; } } const indexs = []; let c = ps; for (let i = 0; i < pageSize; i++) { indexs.push(c); c++; if (c > total) { c = c - total; } } console.log(indexs.join(" ")); console.log(currentSelect); }()