Advertisement
Spocoman

Cinema Voucher

Oct 5th, 2024 (edited)
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.74 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.   "fmt"
  5.   "bufio"
  6.   "os"
  7. )
  8.  
  9. func main() {
  10.     var voucherAmount, ticketPurchased, otherPurchased int
  11.     fmt.Scanln(&voucherAmount)
  12.    
  13.     scanner := bufio.NewScanner(os.Stdin)
  14.    
  15.     for {
  16.         scanner.Scan()
  17.         command := scanner.Text()
  18.         if command == "End" {
  19.             break
  20.         }
  21.         voucherAmount -= int(command[0])
  22.         if voucherAmount < 0 {
  23.             break
  24.         }
  25.         if (len(command) > 8) {
  26.             voucherAmount -= int(command[1])
  27.             if voucherAmount < 0 {
  28.                 break
  29.             }
  30.             ticketPurchased++
  31.         } else {
  32.             otherPurchased++
  33.         }
  34.     }
  35.    
  36.     fmt.Println(ticketPurchased)
  37.     fmt.Println(otherPurchased)
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement