-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathtask.go
More file actions
55 lines (44 loc) · 781 Bytes
/
task.go
File metadata and controls
55 lines (44 loc) · 781 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
package main
import (
"bufio"
"fmt"
"io"
"log"
"os"
"strconv"
"strings"
)
func main() {
s := strings.Builder{}
Solution(os.Stdin, &s)
fmt.Println(s.String())
}
func Solution(r io.Reader, s *strings.Builder) {
scanner := bufio.NewScanner(r)
const bufCapacity = 10000000 // fix long string
buf := make([]byte, bufCapacity)
scanner.Buffer(buf, bufCapacity)
var err error
var n int
scanner.Scan()
n, err = strconv.Atoi(scanner.Text())
if err != nil {
log.Fatal(err)
}
var last, str string
for i := 0; i < n; i++ {
scanner.Scan()
str = scanner.Text()
if i == 0 {
last = str
continue
}
var j, g int
for j < len(last) && g < len(str) && last[j] == str[g] {
j++
g++
}
last = str[:g]
}
s.WriteString(fmt.Sprint(len(last)))
}