输出所有形如aabb的四位完全平方数(即前两位数字相等,后两位数字也相等)。
aabb
无
由小到大输出,每个数占一行。
#include <bits/stdc++.h> using namespace std; bool isSquare(int n) { int tmp=(int)sqrt(n); return tmp*tmp==n; } bool isAABB(int n) { string tmp=to_string(n); return (tmp[0]==tmp[1]&&tmp[2]==tmp[3])? true: false; } int main() { for(int i=1000;i<=9999;i++) { if( isSquare(i) && isAABB(i) ) cout<<i<<endl; } return 0; }