Advertisement
Guest User

Dragon Accounting

a guest
Oct 5th, 2015
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.06 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.CEILING);;
  42.                         if(day>365){
  43.                             int years = (dayCounter-day)/365;
  44.                             for (int i = 0; i < years; i++) {
  45.                                 currentMoney=currentMoney.multiply(BigDecimal.valueOf(0.006));
  46.                             }
  47.                         }
  48.                         BigDecimal currentSalary = currentMoney.multiply(new BigDecimal(countWorkers));
  49.                         capital=capital.subtract(currentSalary.setScale(7, RoundingMode.FLOOR));
  50.                     }
  51.                 }
  52.             }
  53.  
  54.             //firing
  55.             allfired = allfired.add(fired);
  56.             while (!firingOver){
  57.                 for (BigDecimal bigDecimal : employees.get(firingDay).keySet()) {
  58.                     if(fired.compareTo(employees.get(firingDay).get(bigDecimal))>0){
  59.                         fired=fired.subtract(employees.get(firingDay).get(bigDecimal));
  60.                         employees.get(firingDay).replace(bigDecimal,BigInteger.ZERO);
  61.                     }
  62.                     else{
  63.                         BigInteger oldValue = employees.get(firingDay).get(bigDecimal);
  64.                         employees.get(firingDay).replace(bigDecimal,oldValue.subtract(fired));
  65.                         firingOver=true;
  66.                     }
  67.                 }
  68.             }
  69.  
  70.             for (int i = 3; i < commands.length; i++) {
  71.                 String command = commands[i];
  72.                 String money = command.substring(command.indexOf(":")+1);
  73.                 BigDecimal currentIncomeOrExpense =new BigDecimal(money);
  74.                 if(command.contains("Product development")||command.contains("Unconditional funding")){
  75.                     //incomes
  76.                     capital = capital.add(currentIncomeOrExpense);
  77.                 }
  78.                 else{
  79.                     //expense
  80.                     capital=capital.subtract(currentIncomeOrExpense);
  81.                 }
  82.             }
  83.  
  84.             if(capital.compareTo(BigDecimal.ZERO)<0){
  85.                 bancrucy=true;
  86.                 break;
  87.             }
  88.             dayCounter++;
  89.  
  90.             input = scanner.nextLine();
  91.  
  92.         }
  93.  
  94.  
  95.  
  96.         if(bancrucy){
  97.             System.out.println("BANKRUPTCY: " + (capital.multiply(BigDecimal.valueOf(-1)).setScale(4, RoundingMode.FLOOR)));
  98.             return;
  99.         }
  100.  
  101.         System.out.println(allhired.subtract(allfired)+" "+ capital.setScale(4, RoundingMode.FLOOR));
  102.  
  103.  
  104.  
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement