-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy path10098.go
More file actions
57 lines (51 loc) · 917 Bytes
/
10098.go
File metadata and controls
57 lines (51 loc) · 917 Bytes
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
56
57
// UVa 10098 - Generating Fast
package main
import (
"fmt"
"io"
"os"
"sort"
"strings"
)
var (
res map[string]bool
out io.WriteCloser
visited map[int]bool
)
func dfs(strs []string, ans []string) {
if len(ans) == len(strs) {
s := strings.Join(ans, "")
if _, ok := res[s]; !ok {
res[s] = true
fmt.Fprintln(out, s)
}
return
}
for i := range strs {
if !visited[i] {
visited[i] = true
dfs(strs, append(ans, strs[i]))
visited[i] = false
}
}
}
func main() {
in, _ := os.Open("10098.in")
defer in.Close()
out, _ = os.Create("10098.out")
defer out.Close()
var n int
var str string
for fmt.Fscanf(in, "%d", &n); n > 0; n-- {
fmt.Fscanf(in, "%s", &str)
strs := make([]string, len(str))
for i := range str {
strs[i] = string(str[i])
}
sort.Strings(strs)
res = make(map[string]bool)
visited = make(map[int]bool)
dfs(strs, nil)
fmt.Fprintln(out)
}
}