ZJdog @ 2024-04-01 19:43:56
#include<bits/stdc++.h>
using namespace std;
const int N=362885;
int a,b,c;
bool st[N];
int d[N];
void dfs(int x){
if(x>9){
if((d[1]*100+d[2]*10+d[3])*b/a==d[4]*100+d[5]*10+d[6]&&(d[1]*100+d[2]*10+d[3])*c/a==d[7]*100+d[8]*10+d[9]){
for(int j=1;j<=9;j++){
printf("%d",d[j]);
if(j==3||j==6){
printf(" ");
}
}
printf("\n");
}
return;
}
for(int i=1;i<=9;i++){
if(st[i]==false){
d[x]=i;
st[i]= true;
dfs(x+1);
d[x]=0;
st[i]=false;
}
}
}
int main(){
scanf("%d %d %d",&a,&b,&c);
dfs(1);
return 0;
}
by chenshenqi @ 2024-04-01 19:53:32
若无解,输出 No!!!。
by chenshenqi @ 2024-04-01 20:09:08
@ZJdog
#include <bits/stdc++.h>
using namespace std;
bool check(int a,int b,int c){
if (!(a>100&&b>100&&c>100&&a<1000&&b<1000&&c<1000)) return false;
int tmp[9]={a%10,a/10%10,a/100,b%10,b/10%10,b/100,c%10,c/10%10,c/100};
sort(tmp,tmp+9);
if (tmp[0]==0) return false;
for (int i=0; i<8; i++){
if (tmp[i]==tmp[i+1]||tmp[i]==0) return false;
}
return true;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int a,b,c;
cin >> a >> b >> c;
bool flag=false;
for (int i=1; i<=999; i++){
if (check(i*a,i*b,i*c)){
cout << i*a << ' ' << i*b << ' ' << i*c << "\n";
flag=true;
}
}
if (!flag) cout << "No!!!";
return 0;
}
我刚写的
by ZJdog @ 2024-04-01 20:11:03
谢谢哥