Advertisement
Spocoman

Darts

Oct 6th, 2024 (edited)
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.88 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "bufio"
  6.     "os"
  7.     "strconv"
  8. )
  9.  
  10. func main() {
  11.     scanner := bufio.NewScanner(os.Stdin)
  12.     scanner.Scan()
  13.     name := scanner.Text()
  14.  
  15.     scanner.Scan()
  16.     zone := scanner.Text()
  17.      
  18.     var dots, yesCount, noCount int
  19.     total := 301
  20.    
  21.     for total > 0 && zone != "Retire" {
  22.         scanner.Scan()
  23.           dots, _ = strconv.Atoi(scanner.Text())
  24.         if zone == "Double" {
  25.             dots *= 2
  26.         } else if zone == "Triple" {
  27.             dots *= 3
  28.         }
  29.         if total < dots {
  30.             noCount++
  31.         } else {
  32.             total -= dots
  33.             yesCount++
  34.         }
  35.         scanner.Scan()
  36.         zone = scanner.Text()
  37.     }
  38.  
  39.     if total == 0 {
  40.         fmt.Printf("%s won the leg with %d shots.", name, yesCount)
  41.     } else {
  42.         fmt.Printf("%s retired after %d unsuccessful shots.", name, noCount)
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement