Advertisement
Spocoman

Cinema Tickets

Oct 5th, 2024
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.35 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.   "fmt"
  5.   "bufio"
  6.   "os"
  7.   "strconv"
  8. )
  9.  
  10. func main() {
  11.     var kidTickets, studentTickets, standardTickets int  
  12.    
  13.     scanner := bufio.NewScanner(os.Stdin)
  14.    
  15.     for {
  16.         scanner.Scan()
  17.         movie := scanner.Text()
  18.         if movie == "Finish" {
  19.           break
  20.         }
  21.         scanner.Scan()
  22.         seats,_ := strconv.Atoi(scanner.Text())
  23.  
  24.         counter := 0
  25.        
  26.         for i := 0; i < seats; i++ {
  27.             scanner.Scan()
  28.             category := scanner.Text()
  29.             if category == "student" {
  30.                 studentTickets++
  31.             } else if category == "standard" {
  32.                 standardTickets++
  33.             } else if category == "kid" {
  34.                 kidTickets++
  35.             } else {
  36.               break
  37.             }
  38.             counter++
  39.         }
  40.        
  41.         fmt.Printf("%s - %.2f%% full.\n", movie, float64(counter) / float64(seats) * 100)
  42.     }
  43.  
  44.     sumTickets := standardTickets + studentTickets + kidTickets
  45.  
  46.     fmt.Printf("Total tickets: %d\n", sumTickets)
  47.     fmt.Printf("%.2f%% student tickets.\n", float64(studentTickets) / float64(sumTickets) * 100)
  48.     fmt.Printf("%.2f%% standard tickets.\n", float64(standardTickets) / float64(sumTickets) * 100)
  49.     fmt.Printf("%.2f%% kids tickets.\n", float64(kidTickets) / float64(sumTickets) * 100)
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement