HE240214 @ 2024-07-29 14:29:00
#include<bits/stdc++.h>
using namespace std;
const int N=10;
int a,b,c;
bool st[N];
bool check(int u) {
if(u<100||u>999) {
return false;
}
int x=u/100;
int y=u/10%10;
int z=u%10;
if(x==y||y==z||x==z) {
return false;
}
if(st[x]||st[y]||st[z]) {
return false;
}
return st[x]=st[y]=st[z]=true;
}
int main() {
cin>>a>>b>>c;
bool flag=false;
for(int i=123; i<=987; i++) {
memset(st,0,sizeof(st));
st[0]=true;
if(!check(i)) {
continue;
}
if(i*b%a) {
continue;
}
int j=i*b/a;
if(!check(j)) {
continue;
}
int k=j*c/b;
if(!check(k)) {
continue;
}
cout<<i<<' '<<j<<' '<<k<<endl;
flag=true;
}
if(!flag) {
cout<<"No!!!";
}
return 0;
}
by haimingbei @ 2024-07-29 14:40:02
@wuyifan2013 用next_permutation不就行了吗
#include<bits/stdc++.h>
using namespace std;
int main(){
int A,B,C,a[9]={1,2,3,4,5,6,7,8,9};
cin>>A>>B>>C;
bool f=0;
do{
int x=a[0]*100+a[1]*10+a[2];
int y=a[3]*100+a[4]*10+a[5];
int z=a[6]*100+a[7]*10+a[8];
if(x*B==y*A && y*C==z*B)
cout<<x<<" "<<y<<" "<<z<<endl,f=1;
}while(next_permutation(a,a+9));
if(f==0)cout<<"No!!!";
return 0;
}
by HE240214 @ 2024-07-29 14:42:47
@haimingbei 谢谢