-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCCC'00S2.java
More file actions
46 lines (39 loc) · 1.17 KB
/
Copy pathCCC'00S2.java
File metadata and controls
46 lines (39 loc) · 1.17 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
import java.io.*;
import java.util.Scanner;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int input = 0;
int index, length;
double amountFlowing = 0;
double flow;
double hold;
length = sc.nextInt();
ArrayList<Double> rivers = new ArrayList<>();
for (int x = 0; x < length; x++){
rivers.add(x, Double.valueOf(sc.nextInt()));
}
while (input != 77) {
input = sc.nextInt();
if (input == 99){
//split
index = (sc.nextInt())-1;
flow = Double.valueOf((sc.nextInt()));
hold = rivers.get(index);
amountFlowing = (flow/100f) * rivers.get(index);
rivers.set(index, hold - amountFlowing);
rivers.add(index, amountFlowing);
}
if (input == 88){
//join
index = sc.nextInt();
rivers.set(index, rivers.get(index) + rivers.get(index-1));
rivers.remove(index-1);
}
}
for (int x = 0; x < rivers.size(); x++){
System.out.printf("%.0f ",rivers.get(x));
}
}
}