mellowdeep

royal nonstop 100

May 12th, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.06 KB | None | 0 0
  1. import java.math.BigDecimal;
  2. import java.util.Scanner;
  3.  
  4. public class RoyalNonStop {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         try (Scanner scanner = new Scanner(System.in);) {
  9.             scanner.nextInt();
  10.             scanner.nextInt();
  11.             scanner.nextLine();
  12.  
  13.             String[] products = scanner.nextLine().split(" ");
  14.             BigDecimal lukankaPrice = new BigDecimal(products[0]);
  15.             BigDecimal rakijaPrice = new BigDecimal(products[1]);
  16.  
  17.             int custumerCounter = 0;
  18.             BigDecimal moneyEarned = BigDecimal.ZERO;
  19.             String custumer = scanner.nextLine();
  20.  
  21.             while (true) {
  22.                 if (custumer.equals("Royal Close")) {
  23.                     break;
  24.                 }
  25.                 int row = Integer.parseInt(custumer.split(" ")[0]) + 1;
  26.                 int col = Integer.parseInt(custumer.split(" ")[1]) + 1;
  27.                 BigDecimal custumerRow = new BigDecimal(row);
  28.                 BigDecimal custumerCol = new BigDecimal(col);
  29.                 if (row >= col) {
  30.                     for (int i = col; i > 1; i--) {
  31.                         BigDecimal colAmount = custumerRow.multiply(BigDecimal
  32.                                 .valueOf(i));
  33.                         moneyEarned = moneyEarned.add(colAmount
  34.                                 .multiply(row % 2 == 0 ? rakijaPrice
  35.                                         : lukankaPrice));
  36.                     }
  37.                     for (int i = row; i > 1; i--) {
  38.                         BigDecimal rowAmount = BigDecimal.valueOf(i);
  39.                         moneyEarned = moneyEarned.add(rowAmount
  40.                                 .multiply(i % 2 == 0 ? rakijaPrice
  41.                                         : lukankaPrice));
  42.                     }
  43.                 } else {
  44.                     for (int i = row; i > 1; i--) {
  45.                         BigDecimal currentRow = BigDecimal.valueOf(i);
  46.                         BigDecimal rowAmount = currentRow.multiply(custumerCol);
  47.                         moneyEarned = moneyEarned.add(rowAmount
  48.                                 .multiply(i % 2 == 0 ? rakijaPrice
  49.                                         : lukankaPrice));
  50.  
  51.                     }
  52.                     for (int i = col; i > 1; i--) {
  53.  
  54.                         BigDecimal colAmount = BigDecimal.valueOf(i);
  55.                         moneyEarned = moneyEarned.add(colAmount
  56.                                 .multiply(lukankaPrice));
  57.                     }
  58.                 }
  59.                 custumerCounter++;
  60.                 custumer = scanner.nextLine();
  61.  
  62.             }
  63.             System.out.println(moneyEarned
  64.                     .setScale(6, BigDecimal.ROUND_HALF_UP));
  65.             System.out.println(custumerCounter);
  66.         } catch (Exception e) {
  67.             System.out.println(e.toString());
  68.         }
  69.     }
  70. }
Add Comment
Please, Sign In to add comment