Description
希望你找出一个完全平方数出来,它有10位,正好用到0到9这10个数字
Input
无
Output
输出这个数字
DEV C++源码:
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<string> digits = {"9", "8", "7", "6", "5", "4", "3", "2", "1", "0"}; // 包含0到9的数字
long long Number = 0;
string str;
do {
str=accumulate(digits.begin(),digits.end(),string(""));//连接vector中的所有字符串
Number=stoll(str);//转为long long类型
long long sqrtNumber = sqrt(Number);
if (sqrtNumber * sqrtNumber == Number) {
cout << "找到的完全平方数是:" << Number << endl;
return 0;
}
} while (prev_permutation(digits.begin(), digits.end())); // 生成下一个排列(从大到小)
cout << "没有找到符合条件的完全平方数。" << endl;
return 0;
}
运行结果: