65 lines
1.1 KiB
Go
65 lines
1.1 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"bufio"
|
||
|
"fmt"
|
||
|
"io"
|
||
|
"os"
|
||
|
"strconv"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
/*
|
||
|
* Complete the 'miniMaxSum' function below.
|
||
|
*
|
||
|
* The function accepts INTEGER_ARRAY arr as parameter.
|
||
|
*/
|
||
|
|
||
|
func miniMaxSum(arr []int32) {
|
||
|
min := arr[0]
|
||
|
max := arr[0]
|
||
|
sum := int(arr[0])
|
||
|
for _, v := range arr[1:] {
|
||
|
if min > v {
|
||
|
min = v
|
||
|
}
|
||
|
if max < v {
|
||
|
max = v
|
||
|
}
|
||
|
sum += int(v)
|
||
|
}
|
||
|
fmt.Print(sum-int(max), sum-int(min))
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
reader := bufio.NewReaderSize(os.Stdin, 16 * 1024 * 1024)
|
||
|
|
||
|
arrTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
|
||
|
|
||
|
var arr []int32
|
||
|
|
||
|
for i := 0; i < 5; i++ {
|
||
|
arrItemTemp, err := strconv.ParseInt(arrTemp[i], 10, 64)
|
||
|
checkError(err)
|
||
|
arrItem := int32(arrItemTemp)
|
||
|
arr = append(arr, arrItem)
|
||
|
}
|
||
|
|
||
|
miniMaxSum(arr)
|
||
|
}
|
||
|
|
||
|
func readLine(reader *bufio.Reader) string {
|
||
|
str, _, err := reader.ReadLine()
|
||
|
if err == io.EOF {
|
||
|
return ""
|
||
|
}
|
||
|
|
||
|
return strings.TrimRight(string(str), "\r\n")
|
||
|
}
|
||
|
|
||
|
func checkError(err error) {
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
}
|