Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- func main() {
- var balls, red, orange, yellow, white, black, other, totalPoints int
- fmt.Scanln(&balls)
- var color string
- for i := 0; i < balls; i++ {
- fmt.Scanln(&color)
- if color == "red" {
- totalPoints += 5
- red++
- } else if color == "orange" {
- totalPoints += 10
- orange++
- } else if color == "yellow" {
- totalPoints += 15
- yellow++
- } else if color == "white" {
- totalPoints += 20
- white++
- } else if color == "black" {
- totalPoints /= 2
- black++
- } else {
- other++
- }
- }
- fmt.Printf("Total points: %d\n", totalPoints)
- fmt.Printf("Red balls: %d\n", red)
- fmt.Printf("Orange balls: %d\n", orange)
- fmt.Printf("Yellow balls: %d\n", yellow)
- fmt.Printf("White balls: %d\n", white)
- fmt.Printf("Other colors picked: %d\n", other)
- fmt.Printf("Divides from black balls: %d\n", black)
- }
- ИЛИ:
- package main
- import "fmt"
- func main() {
- var balls, red, orange, yellow, white, black, other, totalPoints int
- fmt.Scanln(&balls)
- var color string
- for i := 0; i < balls; i++ {
- fmt.Scanln(&color)
- switch color {
- case "red":
- totalPoints += 5
- red++
- case "orange":
- totalPoints += 10
- orange++
- case "yellow":
- totalPoints += 15
- yellow++
- case "white":
- totalPoints += 20
- white++
- case "black":
- totalPoints /= 2
- black++
- default:
- other++
- }
- }
- fmt.Printf("Total points: %d\n", totalPoints)
- fmt.Printf("Red balls: %d\n", red)
- fmt.Printf("Orange balls: %d\n", orange)
- fmt.Printf("Yellow balls: %d\n", yellow)
- fmt.Printf("White balls: %d\n", white)
- fmt.Printf("Other colors picked: %d\n", other)
- fmt.Printf("Divides from black balls: %d\n", black)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement