-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy path11223.go
More file actions
100 lines (93 loc) · 1.67 KB
/
11223.go
File metadata and controls
100 lines (93 loc) · 1.67 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// UVa 11223 - O: dah dah dah!
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
var morse = map[string]byte{
".-": 'A',
"-...": 'B',
"-.-.": 'C',
"-..": 'D',
".": 'E',
"..-.": 'F',
"--.": 'G',
"....": 'H',
"..": 'I',
".---": 'J',
"-.-": 'K',
".-..": 'L',
"--": 'M',
"-.": 'N',
"---": 'O',
".--.": 'P',
"--.-": 'Q',
".-.": 'R',
"...": 'S',
"-": 'T',
"..-": 'U',
"...-": 'V',
".--": 'W',
"-..-": 'X',
"-.--": 'Y',
"--..": 'Z',
"-----": '0',
".----": '1',
"..---": '2',
"...--": '3',
"....-": '4',
".....": '5',
"-....": '6',
"--...": '7',
"---..": '8',
"----.": '9',
".-.-.-": '.',
"--..--": ',',
"..--..": '?',
".----.": '\'',
"-.-.--": '!',
"-..-.": '/',
"-.--.": '(',
"-.--.-": ')',
".-...": '&',
"---...": ':',
"-.-.-.": ';',
"-...-": '=',
".-.-.": '+',
"-....-": '-',
"..--.-": '_',
".-..-.": '"',
".--.-.": '@',
}
func solve(line string) string {
words := strings.Split(line, " ")
sentence := make([]string, len(words))
for i, word := range words {
letters := strings.Split(word, " ")
chars := make([]byte, len(letters))
for j, letter := range letters {
chars[j] = morse[letter]
}
sentence[i] = string(chars)
}
return strings.Join(sentence, " ")
}
func main() {
in, _ := os.Open("11223.in")
defer in.Close()
out, _ := os.Create("11223.out")
defer out.Close()
s := bufio.NewScanner(in)
s.Split(bufio.ScanLines)
var n int
s.Scan()
fmt.Sscanf(s.Text(), "%d", &n)
for kase := 1; kase <= n && s.Scan(); kase++ {
if kase > 1 {
fmt.Fprintln(out)
}
fmt.Fprintf(out, "Message #%d\n%s\n", kase, solve(s.Text()))
}
}