题解 | #MP3光标位置#

MP3光标位置

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

#include <iostream>
using namespace std;
//更新顶部和底部位置
int main() {
    int n;
    char operation;
    cin>>n;
    int x=1;
    int top=1;
    int bottle=4;
    while(cin>>operation){
        switch(operation){
            case 'U':{
            
                if(x==1)
                {
                    x=n;
                    top=n-3;
                    bottle=n;
                } 
                else if(x==top){
                    x--;
                    top=x;
                    bottle--;
                }else x--;
            
            break;
        }
            case 'D':{
            
                if(x==n)  {
                    x=1;
                    top=1;
                    bottle=4;
                }else if(x==bottle){
                    x++;
                    bottle=x;
                    top++;
                }else x++;
            
            break;
        }
        }        
    }
    if(n<=4){
        int i=1;
        while(n--){
            cout<<i++<<" ";
        }
        cout<<endl;
    }
    else cout<<top<<' '<<top+1<<' '<<top+2<<' '<<top+3<<endl;

    cout<<x<<endl;
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

笑着秋招😊:我一直认为努力有回报是一件很幸福很幸福的事情,恭喜你
点赞 评论 收藏
分享
10-29 19:42
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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