You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
755 B
50 lines
755 B
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"io"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
var spaceReplacer = strings.NewReplacer("\t", "", " ", "")
|
|
|
|
func must(err error) {
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func reachedeof(err error) bool {
|
|
if err != nil {
|
|
if err == io.EOF {
|
|
return true
|
|
} else {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func scanints(str string) []int {
|
|
ints := make([]int, 0)
|
|
scanner := bufio.NewScanner(strings.NewReader(str))
|
|
scanner.Split(bufio.ScanWords)
|
|
|
|
for scanner.Scan() {
|
|
val, err := strconv.Atoi(scanner.Text())
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
ints = append(ints, val)
|
|
}
|
|
return ints
|
|
}
|
|
|
|
// reverses a slice in place
|
|
func reverseSlice[T any](s []T) {
|
|
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
|
|
s[i], s[j] = s[j], s[i]
|
|
}
|
|
}
|
|
|