自己写的1、只移动光标2、普通翻页3、第一首和最后一首互翻
MP3光标位置
https://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextLine()) { String str = in.nextLine(); int n = Integer.valueOf(str); String order = in.nextLine(); int now = 1; int screenUp = 1; int screenDown = 4; if (n < 4) { screenDown = n; } for (int i = 0; i < order.length(); i++) { if (order.charAt(i) == 'U') { if (n <= 4) { if (now == 1) { now = n; } else { now--; } } else { if (now == 1) { now = n; screenDown = n; if (n > 4) { screenUp = n - 3; } } else if (now == screenUp) { now--; screenUp--; screenDown--; } else { now--; } } } else if (order.charAt(i) == 'D') { if (n <= 4) { if (now == n) { now = 1; } else { now++; } } else { if (now == n) { now = 1; screenUp = 1; screenDown = 4; } else if (now == screenDown) { now++; screenUp++; screenDown++; } else { now++; } } } } for (int i = screenUp; i <= screenDown; i++) { System.out.print(i + " "); } System.out.println(); System.out.println(now); } } }