Advertisement
Guest User

Untitled

a guest
Jan 27th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. import java.util.*;
  2. public class J4 {
  3.     private static double[] A = new double[101];
  4.     private static String toString(double[] A) {
  5.         String s = "";
  6.         for(double i : A) {
  7.             if(i > 0.4) {
  8.                 s = s + Math.round(i) + " ";
  9.             }
  10.         } return s;
  11.     }
  12.     private static void split(int x1, double x2) {
  13.         double c1 = A[x1 - 1] * x2 / 100.0;
  14.         double c2 = A[x1 - 1] - c1;
  15.         for(int i = A.length - 2; i >= x1; i--)
  16.             A[i+1] = A[i];
  17.         A[x1] = c2;
  18.         A[x1 - 1] = c1;
  19.     }
  20.     private static void join(int x) {
  21.         double c = A[x] + A[x-1];
  22.         for(int i = x; i < A.length - 1; i++)
  23.             A[i] = A[i+1];
  24.         A[x - 1] = c;
  25.     }
  26.     public static void main(String[] args) {
  27.         Scanner s = new Scanner(System.in);
  28.         int a = s.nextInt();
  29.         for(int i = 0; i < a; i++) {
  30.             A[i] = (double) s.nextInt();
  31.         }
  32.         while(true) {
  33.             int j = s.nextInt();
  34.             if(j == 99) {
  35.                 int x1 = s.nextInt();
  36.                 double x2 = (double)s.nextInt();
  37.                 split(x1, x2);
  38.             }
  39.             if(j == 88) {
  40.                 int x1 = s.nextInt();
  41.                 join(x1);
  42.             }
  43.             if(j == 77) {
  44.                 System.out.println(toString(A));
  45.                 break;
  46.             }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement