Advertisement
Spocoman

Balls

Oct 2nd, 2024 (edited)
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.93 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6.     var balls, red, orange, yellow, white, black, other, totalPoints int
  7.     fmt.Scanln(&balls)
  8.  
  9.     var color string
  10.        
  11.     for i := 0; i < balls; i++ {
  12.         fmt.Scanln(&color)
  13.         if color == "red" {
  14.             totalPoints += 5
  15.             red++
  16.         } else if color == "orange" {
  17.             totalPoints += 10
  18.             orange++
  19.         } else if color == "yellow" {
  20.             totalPoints += 15
  21.             yellow++
  22.         } else if color == "white" {
  23.             totalPoints += 20
  24.             white++
  25.         } else if color == "black" {
  26.             totalPoints /= 2
  27.             black++
  28.         } else {
  29.             other++
  30.         }
  31.     }
  32.  
  33.     fmt.Printf("Total points: %d\n", totalPoints)
  34.     fmt.Printf("Red balls: %d\n", red)
  35.     fmt.Printf("Orange balls: %d\n", orange)
  36.     fmt.Printf("Yellow balls: %d\n", yellow)
  37.     fmt.Printf("White balls: %d\n", white)
  38.     fmt.Printf("Other colors picked: %d\n", other)
  39.     fmt.Printf("Divides from black balls: %d\n", black)
  40. }
  41.  
  42. ИЛИ:
  43.  
  44. package main
  45.  
  46. import "fmt"
  47.  
  48. func main() {
  49.     var balls, red, orange, yellow, white, black, other, totalPoints int
  50.     fmt.Scanln(&balls)
  51.  
  52.     var color string
  53.        
  54.     for i := 0; i < balls; i++ {
  55.         fmt.Scanln(&color)
  56.         switch color {
  57.         case "red":
  58.             totalPoints += 5
  59.             red++
  60.         case "orange":
  61.             totalPoints += 10
  62.             orange++
  63.         case "yellow":
  64.             totalPoints += 15
  65.             yellow++
  66.         case "white":
  67.             totalPoints += 20
  68.             white++
  69.         case "black":
  70.             totalPoints /= 2
  71.             black++
  72.         default:
  73.             other++
  74.         }
  75.     }
  76.  
  77.     fmt.Printf("Total points: %d\n", totalPoints)
  78.     fmt.Printf("Red balls: %d\n", red)
  79.     fmt.Printf("Orange balls: %d\n", orange)
  80.     fmt.Printf("Yellow balls: %d\n", yellow)
  81.     fmt.Printf("White balls: %d\n", white)
  82.     fmt.Printf("Other colors picked: %d\n", other)
  83.     fmt.Printf("Divides from black balls: %d\n", black)
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement