I'm trying to take fast input through scanner.Bytes
and I'm it converting to int. The problem is : input provided is single line spaced elements ( like an array ) and scanner.Bytes
reads it as a whole and converts it into int. How can I use a Splitfunction on the bytes read!
func main() {
scanner := bufio.NewScanner(os.Stdin)
var t int
fmt.Scanf("%d", &t)
for o := 0; o < t; o++ {
scanner.Scan()
//scanner.Split(bufio.ScanWords())
val := toInt(scanner.Bytes())
fmt.Println(val)
}
}
func toInt(buf []byte) (n int) {
for _, v := range buf {
n = n*10 + int(v-'0')
}
return
}