Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "bufio"
- "fmt"
- "os"
- "strconv"
- )
- func main() {
- scanner := bufio.NewScanner(os.Stdin)
- scanner.Scan()
- player1 := scanner.Text()
- scanner.Scan()
- player2 := scanner.Text()
- var card1, card2, point1, point2 int
- scanner.Scan()
- command := scanner.Text()
- for command != "End of game" {
- card1,_ = strconv.Atoi(command)
- scanner.Scan()
- card2,_ = strconv.Atoi(scanner.Text())
- if card1 > card2 {
- point1 += card1 - card2
- } else if card1 < card2 {
- point2 += card2 - card1
- } else {
- scanner.Scan()
- card1,_ = strconv.Atoi(scanner.Text())
- scanner.Scan()
- card2,_ = strconv.Atoi(scanner.Text())
- fmt.Println("Number wars!")
- if card1 > card2 {
- fmt.Printf("%s is winner with %d points", player1, point1)
- } else {
- fmt.Printf("%s is winner with %d points", player2, point2)
- }
- break
- }
- scanner.Scan()
- command = scanner.Text()
- }
- if command == "End of game" {
- fmt.Printf("%s has %d points\n%s has %d points", player1, point1, player2, point2)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement