Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigDecimal;
- import java.math.BigInteger;
- import java.math.RoundingMode;
- import java.util.*;
- public class _2ndDragonAccounting {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- BigDecimal capital = new BigDecimal(scanner.nextLine());
- ArrayList<EmployeeGroup> employees = new ArrayList<>();
- boolean bancrucy = false;
- BigInteger allfired = BigInteger.ZERO;
- BigInteger allhired = BigInteger.ZERO;
- int dayCounter = 1;
- String input = scanner.nextLine();
- while (true){
- if(input.equals("END")){
- break;
- }
- String[] commands = input.split(";");
- BigInteger hired = new BigInteger(commands[0]);
- BigInteger fired = new BigInteger(commands[1]);
- BigDecimal newSalary = new BigDecimal(commands[2]);
- employees.add(new EmployeeGroup(hired, newSalary));
- allhired = allhired.add(hired);
- if(dayCounter%30==0){
- //paySalary
- for (int i = 0; i < employees.size(); i++) {
- EmployeeGroup current = employees.get(i);
- capital=capital.subtract(current.getSalary());
- }
- }
- //firing
- allfired = allfired.add(fired);
- int index = 0;
- while (fired.compareTo(BigInteger.ZERO)<0){
- BigInteger currentCount=employees.get(index).count;
- employees.get(index).count = currentCount.subtract(fired);
- if(employees.get(index).count.compareTo(BigInteger.ZERO)<=0){
- employees.remove(index);
- }
- fired=fired.subtract(currentCount);
- index++;
- }
- for (int i = 3; i < commands.length; i++) {
- String command = commands[i];
- String money = command.substring(command.indexOf(":")+1);
- BigDecimal currentIncomeOrExpense =new BigDecimal(money);
- if(command.contains("Product development")||command.contains("Unconditional funding")){
- //incomes
- capital = capital.add(currentIncomeOrExpense);
- }
- else{
- //expense
- capital=capital.subtract(currentIncomeOrExpense);
- }
- }
- if(capital.compareTo(BigDecimal.ZERO)<0){
- bancrucy=true;
- break;
- }
- dayCounter++;
- for (EmployeeGroup employee : employees) {
- employee.setDay(employee.days+1);
- }
- input = scanner.nextLine();
- }
- if(bancrucy){
- System.out.println("BANKRUPTCY: " + (capital.multiply(BigDecimal.valueOf(-1)).setScale(4, RoundingMode.FLOOR)));
- return;
- }
- System.out.println(allhired.subtract(allfired)+" "+ capital.setScale(4, RoundingMode.FLOOR));
- }
- }
- class EmployeeGroup{
- public BigInteger count;
- public BigDecimal salary;
- public int days;
- public EmployeeGroup(BigInteger count, BigDecimal salary) {
- this.count = count;
- this.salary = salary;
- this.setDay(1);
- }
- public BigDecimal getSalary(){
- BigDecimal daily = calcDailySalary();
- if(days<30){
- return (daily.multiply(new BigDecimal(days))).multiply(new BigDecimal(count));
- }
- return (daily.multiply(new BigDecimal(30))).multiply(new BigDecimal(count));
- }
- private BigDecimal calcDailySalary(){
- return this.salary.divide(new BigDecimal(30),9,RoundingMode.UP).setScale(7, BigDecimal.ROUND_DOWN);
- }
- public void setDay(int days) {
- if(days%365==0){
- salary=salary.multiply(new BigDecimal(1.006));
- }
- this.days = days;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement