题解 | #MP3光标位置#

MP3光标位置

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

#include <iostream>
using namespace std;

int head = 1;


int opRe(char op,int pos,int num){
    if(pos==1 && op=='U'){
        if(num<=4) head=1;
        else head=num-3;
        return num;
    }else if(pos==num && op=='D'){
        if(num<=4) head=1;
        else head=1;
        return 1;
    }else if(op=='D'){
        if(pos+1-head>3){
            head++;
        }
        return pos+1;
    }else{
        if(pos==head){
            head--;
        }
        return pos-1;
    }    
}

int main(){
    int num;
    std::cin >> num;
    string op;
    std::cin >> op;
    int res=1;
    for(auto ch:op){
        res=opRe(ch,res,num);
    }
    int list = min(4,num);
    for(int j=head;j<head+list;j++){
        std::cout << j << " ";
    }
    std::cout << std::endl;
    std::cout << res << std::endl;
    return 0;
}

全部评论

相关推荐

LXXXXd:有点杂,想搞自动化的话没必要把法律的经历写上去
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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