Advertisement
Spocoman

Suitcases Load

Sep 10th, 2024
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         double availableArea = Double.parseDouble(scanner.nextLine());
  7.         int loadedSuitcases = 0;
  8.  
  9.         String input;
  10.         while (!(input = scanner.nextLine()).equals("End")) {
  11.             double currentSuitcaseArea = Double.parseDouble(input);
  12.             if (++loadedSuitcases % 3 == 0) {
  13.                 currentSuitcaseArea *= 1.1;
  14.             }
  15.             if (currentSuitcaseArea > availableArea) {
  16.                 System.out.println("No more space!");
  17.                 loadedSuitcases--;
  18.                 break;
  19.             }
  20.             availableArea -= currentSuitcaseArea;
  21.         }
  22.  
  23.         if (input.equals("End")) {
  24.             System.out.println("Congratulations! All suitcases are loaded!");
  25.         }
  26.         System.out.println("Statistic: " + loadedSuitcases + " suitcases loaded.");
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement