Advertisement
Spocoman

Game Number Wars

Oct 10th, 2024
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.31 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "bufio"
  5.     "fmt"
  6.     "os"
  7.     "strconv"
  8. )
  9.  
  10. func main() {
  11.     scanner := bufio.NewScanner(os.Stdin)
  12.     scanner.Scan()
  13.     player1 := scanner.Text()
  14.    
  15.     scanner.Scan()
  16.     player2 := scanner.Text()
  17.    
  18.     var card1, card2, point1, point2 int
  19.    
  20.     scanner.Scan()
  21.     command := scanner.Text()
  22.    
  23.     for  command != "End of game" {
  24.         card1,_ = strconv.Atoi(command)
  25.         scanner.Scan()
  26.         card2,_ = strconv.Atoi(scanner.Text())
  27.  
  28.         if card1 > card2 {
  29.             point1 += card1 - card2
  30.         } else if card1 < card2 {
  31.             point2 += card2 - card1
  32.         } else {
  33.             scanner.Scan()
  34.             card1,_ = strconv.Atoi(scanner.Text())
  35.            
  36.             scanner.Scan()
  37.             card2,_ = strconv.Atoi(scanner.Text())
  38.  
  39.             fmt.Println("Number wars!")
  40.  
  41.             if card1 > card2 {
  42.                 fmt.Printf("%s is winner with %d points", player1, point1)
  43.             } else {
  44.                 fmt.Printf("%s is winner with %d points", player2, point2)
  45.             }
  46.             break
  47.         }
  48.         scanner.Scan()
  49.         command = scanner.Text()
  50.     }
  51.  
  52.     if command == "End of game" {
  53.         fmt.Printf("%s has %d points\n%s has %d points", player1, point1, player2, point2)
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement