2023-12-04 17:23:02 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"log"
|
|
|
|
"math"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
// readlines reads lines from stdin.
|
|
|
|
// Then it returns them as an array of strings
|
|
|
|
func readlines() []string {
|
|
|
|
lines := []string{}
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(os.Stdin)
|
|
|
|
for scanner.Scan() {
|
|
|
|
lines = append(lines, scanner.Text())
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return lines
|
|
|
|
}
|
|
|
|
|
2023-12-04 18:45:30 +00:00
|
|
|
// compare returns the number of matching elements
|
|
|
|
func compare(a []string, b []string) (int, error) {
|
|
|
|
n := 0
|
|
|
|
for _, elem := range a {
|
|
|
|
if contains(b, elem) {
|
|
|
|
n += 1
|
2023-12-04 17:23:02 +00:00
|
|
|
}
|
|
|
|
}
|
2023-12-04 18:45:30 +00:00
|
|
|
return n, nil
|
2023-12-04 17:23:02 +00:00
|
|
|
}
|
|
|
|
|
2023-12-04 18:45:30 +00:00
|
|
|
// contains returns true if a slice of elements contains a given element
|
2023-12-04 17:23:02 +00:00
|
|
|
func contains[T comparable](elems []T, v T) bool {
|
|
|
|
for _, s := range elems {
|
|
|
|
if v == s {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// pow returns the value of x to the n
|
|
|
|
func pow(x, n int) int {
|
|
|
|
return int(math.Pow(float64(x), float64(n)))
|
|
|
|
}
|