题目中说了是低位数,我们直接倒着取出每一位数字做比较即可,发现不相等,直接break,完成!!!
#include <stdio.h> #include <stdbool.h> int main() { int n; while (scanf("%d", &n) != EOF) { int t = n * n; bool flag = true; while (n) { if (n%10 != t%10) { flag = false; break; } n /= 10; t /= 10; } if (flag) printf("Yes!\n"); else printf("No!\n"); } return 0; }