Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main{
- static List l = new ArrayList();
- static void split(int n, double p) {
- double a = (double) l.get(n - 1);
- double b = a * p / 100;
- double c = a - b;
- l.set(n - 1, b);
- l.add(n, c);
- }
- static void join(int n) {
- double a = (double) l.get(n - 1) + (double) l.get(n);
- l.set(n - 1, a);
- l.remove(n);
- }
- public static void main (String[] args) {
- Scanner s = new Scanner(System.in);
- int n = s.nextInt();
- for (int i = 0; i < n; i++) {
- l.add(s.nextDouble());
- }
- while (s.hasNext()) {
- int a = s.nextInt();
- if (a == 99) {
- split(s.nextInt(), s.nextDouble());
- } else if (a == 88) {
- join(s.nextInt());
- }
- }
- for (int i = 0; i < l.size(); i++) {
- System.out.print(Math.round((double) l.get(i)) + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement