南沙信C++陈老师解一本通题: 2031:【例4.17】四位完全平方数

 题目描述】

输出所有形如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;
}

 

posted @ 2024-09-06 08:29  信奥赛老师  阅读(144)  评论(0)    收藏  举报