Utopia_H @ 2023-04-09 21:19:37
请各位dalao看下,qwq 写的可能比较笨
#include <iostream>
using namespace std;
int main()
{
int flag[11] = {0};
int a, b, c, k1, k2, k3, f = 0;
cin >> k1 >> k2 >> k3;
for (a = 1; a <= 9; a++)
{
flag[a] = 1;
for (b = 1; b <= 9; b++)
{
if (flag[b] == 1)
continue;
else
{
flag[b] = 1;
for (c = 1; c <= 9; c++)
{
if (flag[c] == 1)
continue;
else
{
int t1 = (int)(a * 100 + b * 10 + c) * 1.0 * k2 / k1, t2 = (int)(a * 100 + b * 10 + c) * 1.0 * k3 / k1;
// cout<<a * 100 + b * 10 + c<<" "<<t1<<" "<<t2<<"**************"<<endl;
flag[a]=1,flag[b]=1;
if (t1 < 1000 && t2 < 1000)
{
while (t1)
{
if (flag[t1 % 10])
{
f = 1;
break;
}
flag[t1 % 10]=1;
t1 /= 10;
}
while (t2)
{
if (flag[t2 % 10])
{
f = 1;
break;
}
flag[t2 % 10]=1;
t2 /= 10;
}
if (f == 1)
{
f = 0;
for (int i = 1; i <=10; i++)
{
flag[i]=0;
}
continue;
}
cout << a * 100 + b * 10 + c << " " << (a * 100 + b * 10 + c) * 1.0 * k2/k1 << " " << (a * 100 + b * 10 + c) * 1.0 * k3/k1 << endl;
flag[c] = 0;
}
}
flag[c] = 0;
}
}
flag[b] = 0;
}
flag[a] = 0;
}
}
by hjc999 @ 2023-07-05 11:23:43
有点... 代码:
#include "bits/stdc++.h"
using namespace std;
//记忆化
bool used[10];
int main(){
int a,b,c,ans=0;cin>>a>>b>>c;
for(int d1=1;d1<10;d1++){
if(used[d1])continue;
used[d1]=1;
for(int d2=1;d2<10;d2++){
if(used[d2])continue;
used[d2]=1;
for(int d3=1;d3<10;d3++){
if(used[d3])continue;
used[d3]=1;
for(int d4=1;d4<10;d4++){
if(used[d4])continue;
used[d4]=1;
for(int d5=1;d5<10;d5++){
if(used[d5])continue;
used[d5]=1;
for(int d6=1;d6<10;d6++){
if(used[d6])continue;
used[d6]=1;
for(int d7=1;d7<10;d7++){
if(used[d7])continue;
used[d7]=1;
for(int d8=1;d8<10;d8++){
if(used[d8])continue;
used[d8]=1;
for(int d9=1;d9<10;d9++){
if(used[d9])continue;
used[d9]=1;
int A = d1*100+d2*10+d3;
int B = d4*100+d5*10+d6;
int C = d7*100+d8*10+d9;
if(A*b==B*a and A*c==C*a){
cout<<A<<" "<<B<<" "<<C<<endl;;
ans++;
}
used[d9]=0;
}
used[d8]=0;
}
used[d7]=0;
}
used[d6]=0;
}
used[d5]=0;
}
used[d4]=0;
}
used[d3]=0;
}
used[d2]=0;
}
used[d1]=0;
}
if(!ans)cout<<"No!!!";
}