-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path628.go
55 lines (49 loc) · 870 Bytes
/
628.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
// UVa 628 - Passwords
package main
import (
"fmt"
"io"
"os"
"strings"
)
var (
out io.WriteCloser
dict []string
rule string
)
func dfs(level int, tokens []string) {
if level == len(rule) {
fmt.Fprintln(out, strings.Join(tokens, ""))
return
}
if rule[level] == '#' {
for i := range dict {
dfs(level+1, append(tokens, dict[i]))
}
} else {
for i := '0'; i <= '9'; i++ {
dfs(level+1, append(tokens, string(i)))
}
}
}
func main() {
in, _ := os.Open("628.in")
defer in.Close()
out, _ = os.Create("628.out")
defer out.Close()
var nd, nr int
for {
if _, err := fmt.Fscanf(in, "%d", &nd); err != nil {
break
}
dict = make([]string, nd)
for i := range dict {
fmt.Fscanf(in, "%s", &dict[i])
}
fmt.Fprintln(out, "--")
for fmt.Fscanf(in, "%d", &nr); nr > 0; nr-- {
fmt.Fscanf(in, "%s", &rule)
dfs(0, nil)
}
}
}