题解 | #MP3光标位置#

MP3光标位置

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

//模拟方法

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();
        String str = scan.next();
        int index =1;
        int pageStart = 0;
        for(int i=0;i<str.length();i++){
            if(str.charAt(i) == 'U'){
                if(index -1==0){
                    pageStart = num > 3?num-3:num;    //要点
                    index = num;
                }else{
                    if(index == pageStart){    
                        pageStart -=1;
                    }
                    index -= 1;
                }
            }else{
                if(index +1 == num+1){     //要点
                    pageStart = 1;
                    index = 1;
                }else{
                    if(index == pageStart+3){    //要点
                        pageStart +=1;
                    }
                    index +=1 ;   
                }
            }
        }
        for(int i=0;i<4&&pageStart<=num;i++){
            System.out.print(pageStart+" ");
            pageStart++;
        }
        System.out.println();
        System.out.println(index);
    }
}  、、

#华为机试#
全部评论

相关推荐

06-19 19:06
门头沟学院 Java
码农索隆:别去东软,真学不到东西,真事
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 12:02
ssob上原来真有BOSS啊
硫蛋蛋:这种也是打工的,只不是是给写字楼房东打工
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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