-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMP3Player.java
More file actions
71 lines (65 loc) · 2.15 KB
/
MP3Player.java
File metadata and controls
71 lines (65 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.hw;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
/**
* @author: yhl
* @DateTime: 2020/5/30 20:49
* @Description:
*/
public class MP3Player {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int nums = sc.nextInt();
String opt = sc.next();
int nowSing = 1;
int[] step = new int[opt.length()];
int flag = 0;
for (int i = 0; i < opt.length(); i++) {
if (opt.charAt(i) == 'U') {
if (nowSing == 1) {
nowSing = nums;
flag = 1;
} else {
nowSing--;
}
}
if (opt.charAt(i) == 'D') {
if (nowSing == nums) {
nowSing = 1;
flag = 2;
} else {
nowSing++;
}
}
step[i] = nowSing;
}
// System.out.println(Arrays.toString(step));
List<Integer> list = new ArrayList<>();
for (int i = step.length - 1; i >= 0; i--) {
if (list.size() == 4) {
break;
}
if (list.contains(step[i])) {
continue;
}
list.add(step[i]);
}
boolean isContais = list.contains(1) && list.contains(nums);
if (isContais && list.indexOf(1) < list.indexOf(nums) && nums > 4) {
System.out.print("1 2 3 4");
} else if (isContais && list.indexOf(1) > list.indexOf(nums)) {
System.out.print((nums - 3) + " " + (nums - 2) + " " + (nums - 1) + " " + nums);
} else {
Collections.sort(list);
for (Integer integer : list) {
System.out.print(integer + " ");
}
}
System.out.println("");
System.out.println(nowSing);
}
}
}