Advertisement
Spocoman

08. Equal Pairs

Sep 21st, 2024
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.72 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "math"
  6. )
  7.  
  8. func main() {
  9.     var num, v1, v2, currentValue, currentDiff int
  10.     fmt.Scanln(&num)
  11.     fmt.Scanln(&v1)
  12.     fmt.Scanln(&v2)
  13.    
  14.     var equalValue = v1 + v2
  15.     var maxDiff = 0
  16.  
  17.     for i := 1; i < num; i++ {
  18.         fmt.Scanln(&v1)
  19.         fmt.Scanln(&v2)
  20.         currentValue = v1 + v2
  21.         currentDiff = int(math.Abs(float64(equalValue) - float64(currentValue)))
  22.  
  23.         if currentDiff > maxDiff {
  24.             maxDiff = currentDiff
  25.         } else {
  26.             equalValue = currentValue
  27.         }
  28.     }
  29.      
  30.     if maxDiff == 0 {
  31.         fmt.Printf("Yes, value=%d", equalValue)
  32.     } else {
  33.         fmt.Printf("No, maxdiff=%d", maxDiff)
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement