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

全部评论

相关推荐

07-14 13:37
重庆大学 C++
点赞 评论 收藏
分享
写不来代码的小黑:这么小的城市能有做it的公司也不容易
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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