Advertisement
Spocoman

03. Logistics

Sep 21st, 2024
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.75 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6.     var cargoCount int
  7.     fmt.Scanln(&cargoCount)
  8.  
  9.     var bus = 0.0
  10.     var truck = 0.0
  11.     var train = 0.0
  12.     var totalCargo = 0.0
  13.    
  14.     var cargo float64
  15.  
  16.     for i := 0; i < cargoCount; i++ {
  17.         fmt.Scanln(&cargo)
  18.         if cargo < 4 {
  19.             bus += cargo
  20.         } else if cargo < 12 {
  21.             truck += cargo
  22.         } else {
  23.             train += cargo
  24.         }
  25.         totalCargo += cargo
  26.     }
  27.  
  28.     var average = (bus * 200 + truck * 175 + train * 120) / totalCargo
  29.    
  30.     fmt.Printf("%.2f\n", average)
  31.     fmt.Printf("%.2f%%\n", bus / totalCargo * 100)
  32.     fmt.Printf("%.2f%%\n", truck / totalCargo * 100)
  33.     fmt.Printf("%.2f%%\n", train / totalCargo * 100)
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement