AcWing 3596. golang写法
原题链接
简单
作者:
upupgo
,
2021-07-18 13:10:23
,
所有人可见
,
阅读 287
package main
import (
"fmt"
"strconv"
)
func HpAdd(a string, b string) []int {
cslice := make([]int, 0)
t := 0
aslice := make([]int, 0, len(a))
bslice := make([]int, 0, len(b))
for i := len(a) - 1; i >= 0; i-- {
ai, _ := strconv.Atoi(string(a[i]))
aslice = append(aslice, ai)
}
for i := len(b) - 1; i >= 0; i-- {
bi, _ := strconv.Atoi(string(b[i]))
bslice = append(bslice, bi)
}
for i := 0; i < len(aslice) || i < len(bslice); i++ {
if i < len(aslice) {
t += aslice[i]
}
if i < len(bslice) {
t += bslice[i]
}
cslice = append(cslice, t%10)
t /= 10
}
if t != 0 {
cslice = append(cslice, t)
}
return cslice
}
func main() {
var (
a, b string
)
for {
_, err := fmt.Scan(&a, &b)
if (err != nil) {
break
}
c := HpAdd(a,b)
for i:=len(c)-1;i>=0;i-- {x
fmt.Printf("%d",c[i])
}
fmt.Printf("\n")
}
}