Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- long neededBeers = Long.parseLong(scanner.nextLine()),
- deliveredBeers = 0;
- String input;
- while (!(input = scanner.nextLine()).equals("Exam Over")) {
- int index = input.indexOf(' ');
- long amount = Long.parseLong(input.substring(0, index));
- String type = input.substring(index + 1);
- if (type.equals("sixpacks")) {
- amount *= 6;
- } else if (type.equals("cases")) {
- amount *= 24;
- }
- deliveredBeers += amount;
- }
- deliveredBeers -= deliveredBeers / 100;
- long diff = Math.abs(neededBeers - deliveredBeers),
- cases = diff / 24, sixpacks = diff % 24 / 6, beers = diff % 6;
- if (deliveredBeers >= neededBeers) {
- System.out.printf("Cheers! Beer left: %d cases, %d sixpacks and %d beers.", cases, sixpacks, beers);
- } else {
- System.out.printf("Not enough beer. Beer needed: %d cases, %d sixpacks and %d beers.", cases, sixpacks, beers);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement