Advertisement
Spocoman

Beer Stock

Sep 1st, 2024
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 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.         long neededBeers = Long.parseLong(scanner.nextLine()),
  7.                 deliveredBeers = 0;
  8.         String input;
  9.         while (!(input = scanner.nextLine()).equals("Exam Over")) {
  10.             int index = input.indexOf(' ');
  11.             long amount = Long.parseLong(input.substring(0, index));
  12.             String type = input.substring(index + 1);
  13.             if (type.equals("sixpacks")) {
  14.                 amount *= 6;
  15.             } else if (type.equals("cases")) {
  16.                 amount *= 24;
  17.             }
  18.             deliveredBeers += amount;
  19.         }
  20.  
  21.         deliveredBeers -= deliveredBeers / 100;
  22.         long diff = Math.abs(neededBeers - deliveredBeers),
  23.                 cases = diff / 24, sixpacks = diff % 24 / 6, beers = diff % 6;
  24.  
  25.         if (deliveredBeers >= neededBeers) {
  26.             System.out.printf("Cheers! Beer left: %d cases, %d sixpacks and %d beers.", cases, sixpacks, beers);
  27.         } else {
  28.             System.out.printf("Not enough beer. Beer needed: %d cases, %d sixpacks and %d beers.", cases, sixpacks, beers);
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement