-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy path895.go
More file actions
58 lines (51 loc) · 922 Bytes
/
895.go
File metadata and controls
58 lines (51 loc) · 922 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
58
// UVa 895 - Word Problem
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func buildMap(word string) map[byte]int {
wm := make(map[byte]int)
for i := range word {
wm[word[i]]++
}
return wm
}
func solve(chs string, wordMap map[string]map[byte]int) int {
charMap := buildMap(chs)
var count int
here:
for _, wm := range wordMap {
for c, n := range wm {
if charMap[c] < n {
continue here
}
}
count++
}
return count
}
func main() {
in, _ := os.Open("895.in")
defer in.Close()
out, _ := os.Create("895.out")
defer out.Close()
s := bufio.NewScanner(in)
s.Split(bufio.ScanLines)
var line string
wordMap := make(map[string]map[byte]int)
for s.Scan() {
if line = s.Text(); line == "#" {
break
}
wordMap[line] = buildMap(line)
}
for s.Scan() {
if line = s.Text(); line == "#" {
break
}
fmt.Fprintln(out, solve(strings.Replace(line, " ", "", -1), wordMap))
}
}