Advertisement
Spocoman

Easter Competition

Oct 7th, 2024
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.05 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 easterBreadCount, points, topPoints int
  12.     fmt.Scanln(&easterBreadCount)
  13.    
  14.     var baker, command, topBaker string
  15.    
  16.     scanner := bufio.NewScanner(os.Stdin)
  17.    
  18.     for i := 0; i < easterBreadCount; i++ {
  19.         bakerPoints := 0
  20.        
  21.         scanner.Scan()
  22.         baker = scanner.Text()
  23.        
  24.         scanner.Scan()
  25.         command = scanner.Text()
  26.  
  27.         for command != "Stop" {
  28.             points, _ = strconv.Atoi(command)
  29.             bakerPoints += points
  30.             scanner.Scan()
  31.             command = scanner.Text()
  32.         }
  33.  
  34.         if topPoints < bakerPoints {
  35.             topBaker = baker
  36.             topPoints = bakerPoints
  37.             fmt.Printf("%s has %d points.\n%s is the new number 1!\n", topBaker, topPoints, topBaker)
  38.         } else {
  39.             fmt.Printf("%s has %d points.\n", baker, bakerPoints)
  40.         }
  41.     }
  42.    
  43.     fmt.Printf("%s won competition with %d points!\n", topBaker, topPoints)
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement