Go语言可以用fmt.Scan
和fmt.Println
来读写,但是效率极低,在OJ上可能会TLE。
解决方案是使用bufio
。
func main() {
out := bufio.NewWriter(os.Stdout)defer out.Flush()
in := bufio.NewReader(os.Stdin)func() (x int) {
read_int :=
c, _ := in.ReadByte()for ; c < '0'; c, _ = in.ReadByte() {
}for ; c >= '0'; c, _ = in.ReadByte() {
10 + int(c - '0')
x = x *
}return
}// Your code here
}