-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path10508.go
50 lines (44 loc) · 866 Bytes
/
10508.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
// UVa 10508 - Word Morphing
package main
import (
"fmt"
"os"
)
func getDistance(w1, w2 string) int {
var count int
for i := range w1 {
if w1[i] != w2[i] {
count++
}
}
return count
}
func solve(words []string) map[int]int {
distanceMap := make(map[int]int)
for i := 2; i < len(words); i++ {
distanceMap[getDistance(words[0], words[i])] = i
}
return distanceMap
}
func main() {
in, _ := os.Open("10508.in")
defer in.Close()
out, _ := os.Create("10508.out")
defer out.Close()
var ws, ls int
for {
if _, err := fmt.Fscanf(in, "%d%d", &ws, &ls); err != nil {
break
}
words := make([]string, ws)
for i := range words {
fmt.Fscanf(in, "%s", &words[i])
}
fmt.Fprintln(out, words[0])
distanceMap := solve(words)
for i := 1; i < ls; i++ {
fmt.Fprintln(out, words[distanceMap[i]])
}
fmt.Fprintln(out, words[1])
}
}