Advertisement
Guest User

CCC2000J4

a guest
Jan 26th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Main{
  4.     static List l = new ArrayList();
  5.    
  6.     static void split(int n, double p) {
  7.         double a = (double) l.get(n - 1);
  8.         double b = a * p / 100;
  9.         double c = a - b;
  10.         l.set(n - 1, b);
  11.         l.add(n, c);
  12.     }
  13.    
  14.     static void join(int n) {
  15.         double a = (double) l.get(n - 1) + (double) l.get(n);
  16.         l.set(n - 1, a);
  17.         l.remove(n);
  18.     }
  19.    
  20.     public static void main (String[] args) {
  21.         Scanner s = new Scanner(System.in);
  22.         int n = s.nextInt();
  23.         for (int i = 0; i < n; i++) {
  24.             l.add(s.nextDouble());
  25.         }
  26.         while (s.hasNext()) {
  27.             int a = s.nextInt();
  28.             if (a == 99) {
  29.                 split(s.nextInt(), s.nextDouble());
  30.             } else if (a == 88) {
  31.                 join(s.nextInt());
  32.             }
  33.         }
  34.         for (int i = 0; i < l.size(); i++) {
  35.             System.out.print(Math.round((double) l.get(i)) + " ");
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement