Advertisement
Spocoman

Name Game

Oct 11th, 2024
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.83 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.     var winner string
  16.     var num, points int
  17.  
  18.     for name != "Stop" {
  19.         currentPoints := 0
  20.         for i := 0; i < len(name); i++ {
  21.             scanner.Scan()
  22.             num,_ = strconv.Atoi(scanner.Text())
  23.             z := int(name[i])
  24.  
  25.             if num == z {
  26.                 currentPoints += 10
  27.             } else {
  28.                 currentPoints += 2
  29.             }
  30.         }
  31.        
  32.         if currentPoints >= points {
  33.             winner = name
  34.             points = currentPoints
  35.         }
  36.         scanner.Scan()
  37.         name = scanner.Text()
  38.     }
  39.  
  40.     fmt.Printf("The winner is %s with %d points!", winner, points)
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement