Advertisement
Spocoman

05. Game Of Intervals

Sep 21st, 2024
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.45 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6.     var n int
  7.     fmt.Scanln(&n)
  8.    
  9.     var num0To10 = 0
  10.     var num10To20 = 0
  11.     var num20To30 = 0
  12.     var num30To40 = 0
  13.     var num40To50 = 0
  14.     var invalidNum = 0
  15.     var result = 0.0
  16.    
  17.     var number float64
  18.  
  19.     for i := 0; i < n; i++ {
  20.         fmt.Scanln(&number)
  21.         if number >= 0 && number < 10 {
  22.             result += number * 0.2
  23.             num0To10++
  24.         } else if number >= 10 && number < 20 {
  25.             result += number * 0.3
  26.             num10To20++
  27.         } else if number >= 20 && number < 30 {
  28.             result += number * 0.4
  29.             num20To30++
  30.         } else if number >= 30 && number < 40 {
  31.             result += 50
  32.             num30To40++
  33.         } else if number >= 40 && number <= 50 {
  34.             result += 100
  35.             num40To50++
  36.         } else{
  37.             result /= 2
  38.             invalidNum++
  39.         }
  40.     }
  41.  
  42.     fmt.Printf("%.2f\n", result)
  43.     fmt.Printf("From 0 to 9: %.2f%%\n", float64(num0To10) / float64(n) * 100.0)
  44.     fmt.Printf("From 10 to 19: %.2f%%\n", float64(num10To20) / float64(n) * 100.0)
  45.     fmt.Printf("From 20 to 29: %.2f%%\n", float64(num20To30) / float64(n) * 100.0)
  46.     fmt.Printf("From 30 to 39: %.2f%%\n", float64(num30To40) / float64(n) * 100.0)
  47.     fmt.Printf("From 40 to 50: %.2f%%\n", float64(num40To50) / float64(n) * 100.0)
  48.     fmt.Printf("Invalid numbers: %.2f%%\n", float64(invalidNum) / float64(n * 100))
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement