题解 | #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); } } 、、
#华为机试#