another90sm

Untitled

Apr 14th, 2016
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.79 KB | None | 0 0
  1. import java.math.BigDecimal;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Locale;
  5. import java.util.Scanner;
  6.  
  7. public class DragonAccountant {
  8.  
  9.     public static BigDecimal additionalEvents(String[] events, BigDecimal capital) {
  10.         BigDecimal result = capital;
  11.         for (int i = 3; i < events.length; i++) {
  12.             String[] temp = events[i].split(":");
  13.             switch (temp[0]) {
  14.                 case "Previous years deficit":
  15.                 case "Machines":
  16.                 case "Taxes":
  17.                     result = result.subtract(new BigDecimal(temp[1]));
  18.                     break;
  19.                 case "Product development":
  20.                 case "Unconditional funding":
  21.                     result = result.add(new BigDecimal(temp[1]));
  22.                     break;
  23.             }
  24.         }
  25.         return result;
  26.     }
  27.  
  28.     public static void main(String[] args) {
  29.         Locale.setDefault(new Locale("en", "EN"));
  30.         Scanner scanner = new Scanner(System.in);
  31.         BigDecimal initialCapital = scanner.nextBigDecimal();
  32.         scanner.nextLine();
  33.         long totalHired = 0;
  34.         long totalFired = 0;
  35.         long currentFired = 0;
  36.         int days = 0;
  37.         int startPosition = 0;
  38.         int endPosition = 30;
  39.  
  40.         List<Long> hiredPeople = new ArrayList<>();
  41.         List<BigDecimal> sellaryTable = new ArrayList<>();
  42.  
  43.         String[] input = scanner.nextLine().split(";");
  44.  
  45.         while (!input[0].equals("END")) {
  46.             long hired = Long.parseLong(input[0]);
  47.             totalHired += hired;
  48.             hiredPeople.add(days, hired);
  49.  
  50.             long fired = Long.parseLong(input[1]);
  51.             totalFired += fired;
  52.  
  53.             BigDecimal salary = new BigDecimal(input[2]);
  54.             sellaryTable.add(days, salary);
  55.  
  56.             if (days % 29 == 0) {
  57.                 for (int i = startPosition; i < endPosition; i++) {
  58.                     if (totalFired - hiredPeople.get(i) > 0) {
  59.                         hiredPeople.set(i, 0L);
  60.                         totalFired -= hiredPeople.get(i);
  61.                         startPosition = i;
  62.                     }
  63.                     if (totalFired - hiredPeople.get(i) < 0) {
  64.                         hiredPeople.set(i, Math.abs(totalFired - hiredPeople.get(i)));
  65.                         break;
  66.                     }
  67.                     if (totalFired - hiredPeople.get(i) == 0) {
  68.                         hiredPeople.set(i, 0L);
  69.                         startPosition = i;
  70.                         break;
  71.                     }
  72.                 }
  73.                 endPosition += 30;
  74.  
  75.             }
  76.  
  77.  
  78.             initialCapital = additionalEvents(input, initialCapital);
  79.             input = scanner.nextLine().split(";");
  80.             days++;
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment