Advertisement
Spocoman

Cinema Voucher

Sep 3rd, 2024 (edited)
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 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.         int voucherAmount = Integer.parseInt(scanner.nextLine()),
  7.                 ticketPurchased = 0, otherPurchased = 0;
  8.  
  9.         String command;
  10.         while (!(command = scanner.nextLine()).equals("End")) {
  11.             voucherAmount -= (int) command.charAt(0) + (command.length() > 8 ? (int) command.charAt(1) : 0);
  12.             if (voucherAmount < 0) {
  13.                 break;
  14.             }
  15.             int i = command.length() > 8 ? ticketPurchased++ : otherPurchased++;
  16.         }
  17.  
  18.         System.out.println(ticketPurchased + "\n" + otherPurchased);
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement