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

相关推荐

已经烂了:算法去制造业最少也要211,双非搞算法就是死路一条。至少我在的部门,算法工程师最低都是211毕业的,而且岗位极少。
点赞 评论 收藏
分享
2024-12-27 10:21
已编辑
海南师范大学 媒介策划
到我怀里来:身高体重住址这些就别写了,留几个关键的就行,工作经历突出重点写详细点
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务