题解 | #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);
}()

全部评论

相关推荐

04-03 11:37
武汉大学 Java
高斯林的信徒:武大简历挂?我勒个骚岗
点赞 评论 收藏
分享
03-11 21:46
西北大学 Java
河和静子:这只是实习工资,我学长北大通班博一的,他同学被这家天天发邮件让他去实习,一个月10w
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务