string::npos(一个很大的数)的用法
https://blog.csdn.net/it_beecoder/article/details/69353962
https://www.cnblogs.com/Miranda-lym/p/6357395.html
当==string::npos时,表示找不到匹配的串。
!=表示找到。
/*2013 2 排它平方数*/
#include <iostream>
#include<sstream>
using namespace std;
void iZs(long long x, string &basic_string) {
stringstream ss;
ss << x;
ss >> basic_string;
}
bool check(long long x, long long xx) {
string sx, sxx;
iZs(x, sx);
iZs(xx, sxx);
for (int i = 0; i < sx.length(); i++) {
if (sxx.find(sx[i]) != string::npos)
return false;
}
return true;
}
int main() {
for (int i = 1; i <= 9; i++) {
for (int j = 0; j <= 9; j++) {
if (i != j) {
for (int k = 0; k <= 9; k++) {
if (k != i && k != j) {
for (int p = 0; p <= 9; p++) {
if (p != k && p != j && p != i) {
for (int m = 0; m <= 9; m++) {
if (m != p && m != k && m != j && m != i) {
for (int n = 1; n <= 9; n++) {
if (n != p && n != k && n != j && n != i && n != m) {
long long x = 100000 * i + 10000 * j + 1000 * k + 100 * p + 10 * m + n;
long long xx = x * x;
if (check(x, xx))
cout << x << " " << xx << endl;
}
}
}
}
}
}
}
}
}
}
}
return 0;
}