题解 | #自守数#
自守数
https://www.nowcoder.com/practice/88ddd31618f04514ae3a689e83f3ab8e
package main
import (
"fmt"
"strconv"
)
func main() {
// 接收输入
var count int
fmt.Scan(&count)
// 创建结果数组
var res []int
// 进行循环,这个循环需要包含最后一个值
for i:=0;i<=count;i++{
//将平方转成字符串
tem:=strconv.Itoa(i*i)
// 把对应的i也转成字符串
istr:=strconv.Itoa(i)
// 判断下是否在结尾字符
if tem[len(tem)-len(istr):]==istr{
res = append(res, i)
}
}
fmt.Println(len(res))
}
