Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money

【PTA group Program Design Ladder Competition 】

L1-044 bet (15 points) Go language | Golang

Everyone should be able to play the game of “Hammer, paper, Scissors” : Two people give hand signals at the same time, and the rules are shown below:

Now ask you to write a steady win not lose the program, according to the other party’s move, give the corresponding win. But! To keep your opponent from losing too badly, you need to draw every K times.

Input format:

The input first gives the positive integer K (≤10), the number of draw intervals, on the first line. Then each line gives the opponent a move: ChuiZi for hammer, JianDao for scissors, Bu for paper. End indicates the End of input. This line should not be treated as a move.

Output format:

For each input move, output a sure win or draw move as required. Each move takes one line.

Input Example 1:

2
ChuiZi
JianDao
Bu
JianDao
Bu
ChuiZi
ChuiZi
End
Copy the code

No blank line at the end

Example 1:

Bu
ChuiZi
Bu
ChuiZi
JianDao
ChuiZi
Bu
Copy the code

No blank line at the end

Ideas:

Just use a list to store the answers. And then output it

The code is as follows:

package main

import (
	"fmt"
)

func main(a) {
	var num int
	_,_=fmt.Scan(&num)
	count := 0
	var resultList []string
	for {
		var str string
		_,_=fmt.Scan(&str)
		if str == "End" {  // If it is End, it will exit directly
			break
		}
		if count==2 {  // If count==2, this is a draw
			count=- 1
			resultList = append(resultList, str)
		}else{
			if str=="ChuiZi" {
				resultList = append(resultList, "Bu")}else if str=="JianDao"{
				resultList = append(resultList, "ChuiZi")}else if str=="Bu"{
				resultList = append(resultList, "JianDao")
			}
		}
		count++
	}
	for i:=0; i<len(resultList); i++ {if i == 0 {
			fmt.Printf("%s",resultList[i])
		}else{
			fmt.Printf("\n%s",resultList[i])
		}
	}
}
Copy the code