题解 | #守形数#

守形数

https://www.nowcoder.com/practice/99e403f8342b4d0e82f1c1395ba62d7b

#include <stdio.h>
#include <stdbool.h>

bool isShouxing(int n) {
	int temp1 = n, temp2 = n * n;
	
	while (temp1 > 0) {
		if (temp1 % 10 != temp2 % 10) {
			return false;
		}
		temp1 /= 10;
		temp2 /= 10;
	}

	return true;
}

int main() {
	int n;
	while (scanf("%d", &n) != EOF) {
		if(isShouxing(n)) {
			printf("Yes!\n");
		} else {
			printf("No!\n");
		}
	}
	return 0;
}

全部评论

相关推荐

09-01 21:40
已编辑
同济大学 Java
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务