You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lavos/cap3/ex16.go

23 lines
512 B

package cap3
// Ex16 求x,其平方为一个各位数字互不相同的九位数
func Ex16(callback func(x, x2 int)) {
Next:
4 months ago
for x := 10000; x < 32000; x++ {
numCntMap := map[int]bool{}
4 months ago
x2 := x * x
for i := x2; i >= 1; i /= 10 {
digit := i % 10
// 当前数字已经出现过,直接跳过,找下一个x,如果没出现过,则做标记后看下一位数字情况
if _, exists := numCntMap[digit]; exists {
continue Next
}
4 months ago
numCntMap[digit] = true
}
4 months ago
callback(x, x2)
}
}