题解 | #字符串分隔#
字符串分隔
http://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
package main
import (
"os"
"bufio"
"fmt"
)
var (
in = bufio.NewScanner(os.Stdin)
)
func main() {
res := make([][]string, 0)
for in.Scan() {
s := in.Text()
res = append(res, son(s))
}
for i := 0; i < len(res); i++ {
for _, str := range res[i] {
fmt.Println(str)
}
}
}
func son(s string) []string {
tmp := make([]string, 0, len(s)/8+1)
i, k := 0, 0
if len(s)%8 == 0 {
i = len(s)/8
} else {
i = len(s)/8 + 1
}
for i != 0 {
str := make([]byte, 8)
for j := 0; j < 8; j++ {
if k < len(s) {
str[j] = s[k]; k++
} else {
str[j] = '0'
}
}
tmp = append(tmp, string(str))
i--
}
return tmp
}