Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.93 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.         ArrayList<EmployeeGroup> employees = new ArrayList<>();
  11.         boolean bancrucy = false;
  12.         BigInteger allfired = BigInteger.ZERO;
  13.         BigInteger allhired = BigInteger.ZERO;
  14.         int dayCounter = 1;
  15.         String input = scanner.nextLine();
  16.         while (true){
  17.             if(input.equals("END")){
  18.                 break;
  19.             }
  20.             String[] commands = input.split(";");
  21.             BigInteger hired = new BigInteger(commands[0]);
  22.             BigInteger fired = new BigInteger(commands[1]);
  23.             BigDecimal newSalary = new BigDecimal(commands[2]);
  24.             employees.add(new EmployeeGroup(hired, newSalary));
  25.             allhired = allhired.add(hired);
  26.  
  27.             if(dayCounter%30==0){
  28.                 //paySalary
  29.                 for (int i = 0; i < employees.size(); i++) {
  30.                     EmployeeGroup current = employees.get(i);
  31.                     capital=capital.subtract(current.getSalary());
  32.                 }
  33.             }
  34.  
  35.             //firing
  36.             allfired = allfired.add(fired);
  37.             int index = 0;
  38.             while (fired.compareTo(BigInteger.ZERO)<0){
  39.                 BigInteger currentCount=employees.get(index).count;
  40.                 employees.get(index).count = currentCount.subtract(fired);
  41.                 if(employees.get(index).count.compareTo(BigInteger.ZERO)<=0){
  42.                    employees.remove(index);
  43.                 }
  44.                 fired=fired.subtract(currentCount);
  45.                 index++;
  46.  
  47.             }
  48.  
  49.             for (int i = 3; i < commands.length; i++) {
  50.                 String command = commands[i];
  51.                 String money = command.substring(command.indexOf(":")+1);
  52.                 BigDecimal currentIncomeOrExpense =new BigDecimal(money);
  53.                 if(command.contains("Product development")||command.contains("Unconditional funding")){
  54.                     //incomes
  55.                     capital = capital.add(currentIncomeOrExpense);
  56.                 }
  57.                 else{
  58.                     //expense
  59.                     capital=capital.subtract(currentIncomeOrExpense);
  60.                 }
  61.             }
  62.  
  63.             if(capital.compareTo(BigDecimal.ZERO)<0){
  64.                 bancrucy=true;
  65.                 break;
  66.             }
  67.             dayCounter++;
  68.             for (EmployeeGroup employee : employees) {
  69.                 employee.setDay(employee.days+1);
  70.             }
  71.             input = scanner.nextLine();
  72.  
  73.         }
  74.         if(bancrucy){
  75.             System.out.println("BANKRUPTCY: " + (capital.multiply(BigDecimal.valueOf(-1)).setScale(4, RoundingMode.FLOOR)));
  76.             return;
  77.         }
  78.         System.out.println(allhired.subtract(allfired)+" "+ capital.setScale(4, RoundingMode.FLOOR));
  79.     }
  80. }
  81. class EmployeeGroup{
  82.     public BigInteger count;
  83.     public BigDecimal salary;
  84.     public int days;
  85.  
  86.     public EmployeeGroup(BigInteger count, BigDecimal salary) {
  87.         this.count = count;
  88.         this.salary = salary;
  89.         this.setDay(1);
  90.     }
  91.     public BigDecimal getSalary(){
  92.         BigDecimal daily = calcDailySalary();
  93.         if(days<30){
  94.             return (daily.multiply(new BigDecimal(days))).multiply(new BigDecimal(count));
  95.         }
  96.         return (daily.multiply(new BigDecimal(30))).multiply(new BigDecimal(count));
  97.     }
  98.     private BigDecimal calcDailySalary(){
  99.         return this.salary.divide(new BigDecimal(30),9,RoundingMode.UP).setScale(7, BigDecimal.ROUND_DOWN);
  100.     }
  101.  
  102.     public void setDay(int days) {
  103.         if(days%365==0){
  104.             salary=salary.multiply(new BigDecimal(1.006));
  105.         }
  106.         this.days = days;
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement