-
Notifications
You must be signed in to change notification settings - Fork 3
/
CCC00S2.java
67 lines (62 loc) · 2.12 KB
/
CCC00S2.java
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
import java.util.*;
import java.io.*;
/**
* CCC '00 S2 - Babbling Brooks
* Question type: Simulation
* 5/5 on DMOJ
* @author Tommy Pang
*/
public class CCC00S2 {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st;
static final int MAX = 100;
static int[] result = new int[MAX];
static List<Integer> temp = new ArrayList<>();
public static void main(String[] args) throws IOException {
int N = Integer.parseInt(br.readLine());
for (int i = 0; i < N; i++) {
result[i] = Integer.parseInt(br.readLine());
}
int operation = Integer.parseInt(br.readLine());
while (operation != 77) {
babblingAlg(operation);
operation = Integer.parseInt(br.readLine());
}
for (int nxt : result) {
if (nxt != 0) System.out.print(nxt+" ");
}
}
static void babblingAlg(int operation) throws IOException {
switch (operation) {
case (99):
int idx = Integer.parseInt(br.readLine());
int percentage = Integer.parseInt(br.readLine());
split(idx - 1, percentage);
break;
case (88):
idx = Integer.parseInt(br.readLine());
join(idx - 1);
break;
default:
break;
}
}
private static void split(int idx, int percentage) {
int[] suf = result.clone();
if (percentage == 0) return;
int left = Math.round(result[idx] * ((float) percentage / 100));
int right = Math.round(result[idx] * (float) (100 - percentage) / 100);
result[idx] = left;
result[idx + 1] = right;
for (int i = idx + 2; i < MAX; i++) {
result[i] = suf[i - 1];
}
}
private static void join(int idx) {
int[] suf = result.clone();
result[idx] = result[idx] + result[idx + 1];
for (int i = idx + 1; i < MAX-1; i++) {
result[i] = suf[i + 1];
}
}
}