-
Notifications
You must be signed in to change notification settings - Fork 4
/
judge.go
55 lines (50 loc) · 1.05 KB
/
judge.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"bufio"
"fmt"
"io"
"os"
"regexp"
"strings"
)
const (
WA = 1
SE = 8
)
var cas = os.Getenv("case")
var num = regexp.MustCompile(`\d+`)
func quit(s int, v ...any) {
fmt.Fprintln(os.Stderr, v...)
os.Exit(s)
}
func main() {
var in, ans *os.File
if ds, e := os.ReadDir("."); e == nil {
for _, d := range ds {
if !d.IsDir() && num.FindString(d.Name()) == cas {
switch {
case strings.Contains(d.Name(), "in"):
in, _ = os.Open(d.Name())
case strings.Contains(d.Name(), "ou") || strings.Contains(d.Name(), "an"):
ans, _ = os.Open(d.Name())
}
}
}
}
if in == nil || ans == nil {
quit(SE, "unable to get data")
}
if _, e := io.Copy(os.Stdout, in); e != nil {
quit(SE, e)
}
asc, osc := bufio.NewScanner(ans), bufio.NewScanner(os.Stdin)
for i := 0; ; i++ { // do not use `asc.Scan() || osc.Scan()`
ok1, ok2 := asc.Scan(), osc.Scan()
if !ok1 && !ok2 {
break
}
if strings.TrimRight(asc.Text(), " \r\n") != strings.TrimRight(osc.Text(), " \r\n") {
quit(WA, "wrong answer at line", i+1)
}
}
}