forked from charlesfranciscodev/codingame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ascii-art.go
37 lines (32 loc) · 808 Bytes
/
ascii-art.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
package main
import "fmt"
import "os"
import "bufio"
import "strings"
func main() {
scanner := bufio.NewScanner(os.Stdin)
scanner.Buffer(make([]byte, 1000000), 1000000)
var width int
scanner.Scan()
fmt.Sscan(scanner.Text(), &width)
var height int
scanner.Scan()
fmt.Sscan(scanner.Text(), &height)
scanner.Scan()
var text = strings.ToUpper(scanner.Text())
for i := 0; i < height; i++ {
scanner.Scan()
var row = scanner.Text()
var output = "" // could use strings.Builder instead
for _, r := range text {
var position = int(r - 'A')
if (position < 0 || position > 25) {
position = 26
}
var start = position * width
var end = start + width
output += row[start:end] // ASCII substring
}
fmt.Println(output)
}
}