题解 | #MP3光标位置#
MP3光标位置
https://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
纯模拟,如果仔细看下去就会有窗口移动的画面,可能也算是滑动窗口
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNext()) { // 注意 while 处理多个 case int n = Integer.parseInt(in.nextLine()); String flags = in.nextLine(); int start = 1; int end = Math.min(4,n); int local = 1; for (Character flag : flags.toCharArray()) { if (flag == 'U') { if(local == start){ if(local == 1){ local = n; end = n; start = Math.max(1,n-3); }else{ local--; start--; end--; } }else{ local--; } } else { if(local == end){ if(local == n){ local = 1; start = 1; end = Math.min(4,n); }else{ start++; end++; local++; } }else{ local++; } } } for(int i = start;i<=end;i++){ System.out.print(i+" "); } System.out.print("\n" + local); } } }