-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner.go
45 lines (38 loc) · 809 Bytes
/
runner.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
package main
import (
"fmt"
"os"
"errors"
)
func main() {
if err := run(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func run() error {
if len(os.Args) != 2 {
return errors.New("expected exactly one program argument (problem name)")
}
solvers := map[string]func() (string, error){
"problema": SolveA,
"problemb": SolveB,
}
problem := os.Args[1]
solver, exist := solvers[problem];
if !exist {
return fmt.Errorf("unknown problem '%v'. Solver for this problem not found", problem)
}
var cases int
if _, err := fmt.Scan(&cases); err != nil {
return fmt.Errorf("unable to read number of test cases. Error: '%v'", err)
}
for i := 0; i < cases; i++ {
result, err := solver();
if err != nil {
return err
}
fmt.Printf("Case #%d: %s\n", i+1, result)
}
return nil
}