Last active
February 23, 2017 19:50
-
-
Save gerep/3cec17505541f7849c165dc0435ec86a to your computer and use it in GitHub Desktop.
Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"os" | |
"sort" | |
"strconv" | |
"strings" | |
) | |
func main() { | |
// Read from Stdin | |
b := bufio.NewReader(os.Stdin) | |
l, _, err := b.ReadLine() | |
if err != nil { | |
panic(err) | |
} | |
// Split converted buffer | |
n := strings.Split(string(l), " ") | |
// Convert number from string to int into the array | |
intList := []int{0, 0, 0, 0, 0} | |
for x := 0; x < 5; x++ { | |
i, err := strconv.Atoi(n[x]) | |
if err != nil { | |
panic(err) | |
} | |
intList[x] = i | |
} | |
sort.Ints(intList) | |
sum := 0 | |
for x := 0; x < 5; x++ { | |
sum += intList[x] | |
} | |
lower := sum - intList[4] | |
higher := sum - intList[0] | |
fmt.Printf("%d %d", lower, higher) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment