Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigDecimal;
- import java.util.Scanner;
- public class RoyalNonStop {
- public static void main(String[] args) {
- try (Scanner scanner = new Scanner(System.in);) {
- scanner.nextInt();
- scanner.nextInt();
- scanner.nextLine();
- String[] products = scanner.nextLine().split(" ");
- BigDecimal lukankaPrice = new BigDecimal(products[0]);
- BigDecimal rakijaPrice = new BigDecimal(products[1]);
- int custumerCounter = 0;
- BigDecimal moneyEarned = BigDecimal.ZERO;
- String custumer = scanner.nextLine();
- while (true) {
- if (custumer.equals("Royal Close")) {
- break;
- }
- int row = Integer.parseInt(custumer.split(" ")[0]) + 1;
- int col = Integer.parseInt(custumer.split(" ")[1]) + 1;
- BigDecimal custumerRow = new BigDecimal(row);
- BigDecimal custumerCol = new BigDecimal(col);
- if (row >= col) {
- for (int i = col; i > 1; i--) {
- BigDecimal colAmount = custumerRow.multiply(BigDecimal
- .valueOf(i));
- moneyEarned = moneyEarned.add(colAmount
- .multiply(row % 2 == 0 ? rakijaPrice
- : lukankaPrice));
- }
- for (int i = row; i > 1; i--) {
- BigDecimal rowAmount = BigDecimal.valueOf(i);
- moneyEarned = moneyEarned.add(rowAmount
- .multiply(i % 2 == 0 ? rakijaPrice
- : lukankaPrice));
- }
- } else {
- for (int i = row; i > 1; i--) {
- BigDecimal currentRow = BigDecimal.valueOf(i);
- BigDecimal rowAmount = currentRow.multiply(custumerCol);
- moneyEarned = moneyEarned.add(rowAmount
- .multiply(i % 2 == 0 ? rakijaPrice
- : lukankaPrice));
- }
- for (int i = col; i > 1; i--) {
- BigDecimal colAmount = BigDecimal.valueOf(i);
- moneyEarned = moneyEarned.add(colAmount
- .multiply(lukankaPrice));
- }
- }
- custumerCounter++;
- custumer = scanner.nextLine();
- }
- System.out.println(moneyEarned
- .setScale(6, BigDecimal.ROUND_HALF_UP));
- System.out.println(custumerCounter);
- } catch (Exception e) {
- System.out.println(e.toString());
- }
- }
- }
Add Comment
Please, Sign In to add comment