题解 | #MP3光标位置#

MP3光标位置

https://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int num;
    int curPos = 1;
    string  command;
    cin >> num >> command;
    int winBegin = 1;
    int winEnd = min(num, 4);
    
    for(int i = 0; i < command.length(); i++){
        if(command[i] == 'U') curPos = (curPos - 2 + num) % num + 1;
        if(command[i] == 'D') curPos = curPos % num + 1;
        
        if(winBegin > curPos){//特殊翻页D和一般翻页U
            winBegin = curPos;
            winEnd = winBegin + 3;
        }
        if(winEnd < curPos){//特殊翻页U和一般翻页D
            winEnd = curPos;
            winBegin = winEnd - 3;
        }
    }
    for(int i = winBegin; i <= winEnd; i++) cout << i << " ";
    cout  << endl;
    cout << curPos << endl;
    return 0;
}

全部评论

相关推荐

04-28 10:14
门头沟学院 Java
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务