题目
题解
代码
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3;
string ans[N]; // 排序输出
int vis[10], cnt;
map<string, bool> mp; // 找过的字符串就不再添加到ans数组中了
bool cmp(string a, string b) {
return a < b;
}
int main()
{
ans[++cnt] = "123456789";
ans[++cnt] = "918273645";
for(int i = 100;i <= 333;i ++) { // 三位数 * 1~3
memset(vis, 0, sizeof vis);
int x = i, y = i*2, z = i*3, sum = 0;
string s;
while(z) { vis[z%10] = 1; s=char(z%10+'0') + s; z/=10; }
while(y) { vis[y%10] = 1; s=char(y%10+'0') + s; y/=10; }
while(x) { vis[x%10] = 1; s=char(x%10+'0') + s; x/=10; }
for(int i = 1;i < 10;i ++) sum += vis[i];
if(sum == 9 && !mp[s]) ans[++cnt] = s, mp[s] = 1;
}
for(int i = 5000;i < 10000;i ++) { // 四位数 * 1~2
memset(vis, 0, sizeof vis);
int x = i, y = i*2, sum = 0;
string s;
while(y) { vis[y%10] = 1; s=char(y%10+'0') + s; y/=10; }
while(x) { vis[x%10] = 1; s=char(x%10+'0') + s; x/=10; }
for(int i = 1;i < 10;i ++) sum += vis[i];
if(sum == 9 && !mp[s]) ans[++cnt] = s, mp[s] = 1;
}
sort(ans+1, ans+cnt+1, cmp);
for(int i = 1;i <= cnt;i ++) puts(ans[i].c_str());
return 0;
}
/*
123456789 //
192384576
219438657
273546819
327654981
672913458
679213584
692713854
726914538
729314586
732914658
769215384
792315846
793215864
918273645 //
926718534
927318546
932718654
*/