forked from charlesfranciscodev/codingame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmime-type.go
47 lines (41 loc) · 1.02 KB
/
mime-type.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
package main
import (
"fmt"
"os"
"bufio"
"strings"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
scanner.Buffer(make([]byte, 1000000), 1000000)
// dictionary to map file extensions to mime types
var table = make(map[string]string)
var nbElements int
scanner.Scan()
fmt.Sscan(scanner.Text(), &nbElements)
var nbNames int
scanner.Scan()
fmt.Sscan(scanner.Text(), &nbNames)
for i := 0; i < nbElements; i++ {
var extension, mimeType string
scanner.Scan()
fmt.Sscan(scanner.Text(), &extension, &mimeType)
table[strings.ToLower(extension)] = mimeType
}
for i := 0; i < nbNames; i++ {
scanner.Scan()
name := strings.ToLower(scanner.Text())
var dotIndex = strings.LastIndex(name, ".")
if dotIndex == -1 || dotIndex == len(name) - 1 {
fmt.Println("UNKNOWN")
} else {
var extension = name[dotIndex + 1:]
mimeType, ok := table[extension]
if ok {
fmt.Println(mimeType)
} else {
fmt.Println("UNKNOWN")
}
}
}
}