Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Debugging {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int voucher = Integer.parseInt(scanner.nextLine());
  8.         String purchase = scanner.nextLine();
  9.  
  10.         int countPurchases = 0;
  11.         int countTicketsPurchased = 0;
  12.  
  13.         while (!"End".equals(purchase)) {
  14.             int symbolToNumOne = (int) purchase.charAt(0);
  15.             int symbolToNumTwo = (int) purchase.charAt(1);
  16.  
  17.             if (purchase.length() > 8) {
  18.                 if ((symbolToNumOne + symbolToNumTwo) <= voucher) {
  19.                     countTicketsPurchased++;
  20.                     voucher -= (symbolToNumOne + symbolToNumTwo);
  21.                 }else {
  22.                     break;
  23.                 }
  24.             } else {
  25.                 if (symbolToNumOne <= voucher) {
  26.                     countPurchases++;
  27.                     voucher -=  symbolToNumOne;
  28.                 }
  29.                 else {
  30.                     break;
  31.                 }
  32.             }
  33.             purchase = scanner.nextLine();
  34.         }
  35.         System.out.printf("%d\n%d", countTicketsPurchased, countPurchases);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement