linlin6 @ 2022-12-14 21:38:09
#include<iostream>
using namespace std;
int p,q,r,a,b,c,num,n[10],t=0;
void chai(int x)
{
while (x != 0)
{
num = x % 10;
x = x / 10;
n[num]++;
}
}
int main()
{
cin >> p >> q >> r;
if (p < q && q < r)
{
for (int i = 1; i <= 9; i++)
for (int j = 1; j <= 9; j++)
for (int k = 1; k <= 9; k++)
{
a = 100 * i + 10 * j + k;
b = (q / p) * a;
c = (r / p) * a;
chai(a);
chai(b);
chai(c);
if (n[1] == 1 && n[2] == 1 && n[3] == 1 && n[4] == 1 && n[5] == 1 && n[6] == 1 && n[1] == 1 && n[7] == 1 && n[8] == 1 && n[9] == 1)
{
cout << a << " " << b << " " << c << endl;
t++;
}
for (int m = 0; m <= 9; m++)
{
n[m] = 0;
}
}
if (t == 0)
cout << "No!!!";
}
return 0;
}
by bobosolomon @ 2022-12-16 14:32:35
如果p q r 不符合要求p < q && q < r
,那么,你这个只会输出No!!!
;这样是不对的,你可以枚举1-1000的每一个数,然后a,b,c分别a = i * p, b = i * q, c = i * r
,那么再用你那个是可以的。
by shuyuan2016 @ 2022-12-18 17:27:46
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int a[10];
int A,B,C;
int main(){
cin>>A>>B>>C;
for(int i=1;i<=9;i++)a[i]=i;
int cnt=0;
do{
int x,y,z;
x=100*a[1]+10*a[2]+a[3];
y=100*a[4]+10*a[5]+a[6];
z=100*a[7]+10*a[8]+a[9];
if(y*A==B*x&&A*z==C*x){
printf("%d %d %d\n",x,y,z);
cnt++;}
}while(next_permutation(a+1,a+10));
if(cnt==0)cout<<"No!!!";
return 0;
}
by int_stl @ 2022-12-21 18:34:30
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
int a[10];
int main() {
LL A, B, C, x, y, z, cnt = 0;
cin >> A >> B >> C;
if (A == 0 && B == 0 && C == 0) {
cout << "No!!!";
return 0;
}
for (int i = 1; i <= 9; i++) {
a[i] = i;
}
do {
x = a[1] * 100 + a[2] * 10 + a[3];
y = a[4] * 100 + a[5] * 10 + a[6];
z = a[7] * 100 + a[8] * 10 + a[9];
if (x * B == y * A && y * C == z * B) {
cout << x << " " << y << " " << z << endl, cnt++;
}
} while (next_permutation(a + 1, a + 10));
if (!cnt) cout << "No!!!";
}