/
P9996.go
57 lines (48 loc) · 889 Bytes
/
P9996.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
56
57
// Regular Expression
// https://www.acmicpc.net/problem/9996
package main
import (
"bufio"
"bytes"
"fmt"
"os"
"regexp"
"strconv"
)
var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var bw *bufio.Writer = bufio.NewWriter(os.Stdout)
func Fn() {
N, pattern := scanInt(), scanString()
var exp bytes.Buffer
exp.WriteString("^")
for i := 0; i < len(pattern); i++ {
if pattern[i] == 42 {
exp.WriteString("[a-z]*")
} else {
exp.WriteString(string(pattern[i]))
}
}
exp.WriteString("$")
Exp, _ := regexp.Compile(exp.String())
for i := 0; i < N; i++ {
if Exp.MatchString(scanString()) {
fmt.Fprintln(bw, "DA")
} else {
fmt.Fprintln(bw, "NE")
}
}
}
func main() {
defer bw.Flush()
sc.Split(bufio.ScanWords)
Fn()
}
func scanString() string {
sc.Scan()
return sc.Text()
}
func scanInt() int {
sc.Scan()
v, _ := strconv.Atoi(sc.Text())
return v
}