Advertisement
Guest User

Untitled

a guest
Oct 5th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.58 KB | None | 0 0
  1. import java.math.BigDecimal;
  2. import java.math.BigInteger;
  3. import java.math.RoundingMode;
  4. import java.util.*;
  5.  
  6. public class _2ndDragonAccounting {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.         BigDecimal capital = new BigDecimal(scanner.nextLine());
  10.         LinkedHashMap<Integer,LinkedHashMap<BigDecimal,BigInteger>> employees = new LinkedHashMap<>();
  11.         boolean bancrucy = false;
  12.         boolean firingOver = false;
  13.         int firingDay=1;
  14.         BigInteger allfired = BigInteger.ZERO;
  15.         BigInteger allhired = BigInteger.ZERO;
  16.         int dayCounter = 1;
  17.         String input = scanner.nextLine();
  18.         while (true){
  19.  
  20.             if(input.equals("END")){
  21.                 break;
  22.             }
  23.             String[] commands = input.split(";");
  24.             BigInteger hired = new BigInteger(commands[0]);
  25.             BigInteger fired = new BigInteger(commands[1]);
  26.             BigDecimal newSalary = new BigDecimal(commands[2]);
  27.             if(!employees.containsValue(hired)){
  28.             employees.put(dayCounter,new LinkedHashMap<>());
  29.             }
  30.  
  31.             employees.get(dayCounter).put(newSalary,hired);
  32.             allhired = allhired.add(hired);
  33.  
  34.             if(dayCounter%30==0){
  35.                 //paySalary
  36.                 for (int day : employees.keySet()) {
  37.  
  38.                     for (BigDecimal money : employees.get(day).keySet()) {
  39.  
  40.                         BigInteger countWorkers = employees.get(day).get(money);
  41.                         BigDecimal currentMoney = money.setScale(9, RoundingMode.UP);
  42.                         BigDecimal dailySalary = currentMoney.divide(new BigDecimal(30), 9, BigDecimal.ROUND_UP);
  43.                         BigDecimal currentSalary=BigDecimal.ZERO;
  44.                         if (day < 30) {
  45.                             currentSalary = currentSalary.add(dailySalary.multiply(new BigDecimal(day)));
  46.                         }
  47.                         else {
  48.                             if(day>365){
  49.                                 int years = (dayCounter-day)/365;
  50.                                 for (int i = 0; i < years; i++) {
  51.                                     dailySalary=dailySalary.multiply(BigDecimal.valueOf(0.006));
  52.                                 }
  53.                             }
  54.                             currentSalary = currentSalary.add(dailySalary.multiply(new BigDecimal(30)));
  55.                         }
  56.  
  57.                         currentSalary=currentSalary.multiply(new BigDecimal(countWorkers));
  58.                         capital=capital.subtract(currentSalary.setScale(7, BigDecimal.ROUND_FLOOR));
  59.                     }
  60.                 }
  61.             }
  62.  
  63.             //firing
  64.             allfired = allfired.add(fired);
  65.             while (!firingOver){
  66.                 for (BigDecimal bigDecimal : employees.get(firingDay).keySet()) {
  67.                     if(fired.compareTo(employees.get(firingDay).get(bigDecimal))>0){
  68.                         fired=fired.subtract(employees.get(firingDay).get(bigDecimal));
  69.                         employees.get(firingDay).replace(bigDecimal,BigInteger.ZERO);
  70.                     }
  71.                     else{
  72.                         BigInteger oldValue = employees.get(firingDay).get(bigDecimal);
  73.                         employees.get(firingDay).replace(bigDecimal,oldValue.subtract(fired));
  74.                         firingOver=true;
  75.                     }
  76.                 }
  77.             }
  78.  
  79.             for (int i = 3; i < commands.length; i++) {
  80.                 String command = commands[i];
  81.                 String money = command.substring(command.indexOf(":")+1);
  82.                 BigDecimal currentIncomeOrExpense =new BigDecimal(money);
  83.                 if(command.contains("Product development")||command.contains("Unconditional funding")){
  84.                     //incomes
  85.                     capital = capital.add(currentIncomeOrExpense);
  86.                 }
  87.                 else{
  88.                     //expense
  89.                     capital=capital.subtract(currentIncomeOrExpense);
  90.                 }
  91.             }
  92.  
  93.             if(capital.compareTo(BigDecimal.ZERO)<0){
  94.                 bancrucy=true;
  95.                 break;
  96.             }
  97.             dayCounter++;
  98.  
  99.             input = scanner.nextLine();
  100.  
  101.         }
  102.  
  103.  
  104.  
  105.         if(bancrucy){
  106.             System.out.println("BANKRUPTCY: " + (capital.multiply(BigDecimal.valueOf(-1)).setScale(4, RoundingMode.FLOOR)));
  107.             return;
  108.         }
  109.  
  110.         System.out.println(allhired.subtract(allfired)+" "+ capital.setScale(4, RoundingMode.FLOOR));
  111.  
  112.  
  113.  
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement