题解 | #MP3光标位置#

MP3光标位置

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

package com.huawei;
import java.util.*;

public class guangbiao {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int nums = input.nextInt();
        input.nextLine();
        String op = input.nextLine();
        int low = 1, high = 4;
        int now = 1;
        if(nums <= 4){
            low = 1; high = nums;
            for(char opp : op.toCharArray()){
                if(opp == 'U'){
                    now--;
                    if(now == low - 1){
                        now = high;
                    }
                }else{
                    now++;
                    if(now == high + 1){
                        now = low;
                    }
                }
            }
        }else{
            for(char opp : op.toCharArray()){
                if(opp == 'U'){
                    now--;
                    if(now == 0){
                        now = nums;
                        low = nums - 3;
                        high = nums;
                    }
                    else if(now == low - 1){
                        low--;
                        high--;
                    }
                }else{
                    now++;
                    if(now == nums + 1){
                        now = 1;
                        low = now;
                        high = now + 3;
                    }else if(now == high + 1){
                        high++;
                        low++;
                    }
                }
            }
        }
        for (int i = low; i <= high; i++) {
            System.out.print(i + " ");
        }
        System.out.println();
        System.out.println(now);
    }


}

#华为笔试#
全部评论
农研属于总行下属一级机构
点赞 回复 分享
发布于 2022-07-21 17:38

相关推荐

再挂就要开播了😭:活不了了,一打开就看到这么厉害的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务