题目链接:https://www.luogu.org/problem/P1618
思路:
? 判断三个数的每一位加起来是否等于从1加到9,且每一位相乘是否等于从1乘到9;
代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int a,b,c,max,b1,c1,t1,t2,t3,i,t=0,l;
cin>>a>>b>>c;
if(c%a==0&&a!=1&&b%a==0){ //判断是否出现例如2:4:6的情况;
l = a;
a = a/l;
b = b/l;
c = c/l;
}
max = c;
if(a>=123){ //判读是否出现例如123:456:789的情况;//注意!!!!!!
t1 = a/10;
t2 = b/10;
t3 = c/10;
if(t1/10+t1%10+a%10+t2/10+t2%10+b%10+t3/10+t3%10+c%10==45&&(t1/10)*(t1%10)*(a%10)*(t2/10)*(t2%10)*(b%10)*(t3/10)*(t3%10)*(c%10)==(1*2*3*4*5*6*7*8*9)){
cout<<a<<" "<<b<<" "<<c<<endl;
t = 1;
}
}else{
for(i=123;i<=999/max;i++){
if(i%a==0){
b1 = (i/a)*b;
c1 = (i/a)*c;
t1 = i/10;
t2 = b1/10;
t3 = c1/10;
if(t1/10+t1%10+i%10+t2/10+t2%10+b1%10+t3/10+t3%10+c1%10==45&&(t1/10)*(t1%10)*(i%10)*(t2/10)*(t2%10)*(b1%10)*(t3/10)*(t3%10)*(c1%10)==(1*2*3*4*5*6*7*8*9)){
cout<<i<<" "<<b1<<" "<<c1<<endl;
t = 1;
}
}
}
}
if(t==0){
cout<<"No!!!"<<endl;
}
return 0;
}
原文:https://www.cnblogs.com/zz9100/p/11255526.html