AcWing 794. 高精度除法
原题链接
简单
作者:
Entropy
,
2021-03-01 22:28:19
,
所有人可见
,
阅读 261
题目描述
GO代码
package main
import (
"fmt"
"strconv"
)
func main() {
var a string
var b int
fmt.Scanf("%s", &a)
fmt.Scanf("%d", &b)
va := make([]int, len(a))
for i, v := range a {
t, _ := strconv.Atoi(fmt.Sprintf("%c", v)) //ascii byte -> int
va[i] = t
}
res, yu := helper(va, b)
flag := true
for i, r := range res {
//去除前置0
if flag == true && i != len(res) - 1 && r == 0 {
continue
} else {
flag = false
}
fmt.Printf("%d", r)
}
fmt.Printf("\n%d", yu)
}
func helper(va[]int, b int) ([]int, int) {
res := make([]int, 0)
r := 0
for i := 0; i < len(va); i++ {
r = r * 10 + va[i]
res = append(res, r / b)
r %= b
}
return res, r
}
强