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