题目描述
将 1,2,…,9共 9个数分成 3 组,分别组成 3 个三位数,且使这 3 个三位数构成 1:2:3 的比例,试求出所有满足条件的 3 个三位数。
输入格式
无
输出格式
若干行,每行 3 个数字。按照每行第 1 个数字升序排列。
代码
#include<bits/stdc++.h>
using namespace std;
int main(){
int a[10]={};
for(int i=100;i<=333;i++){
int x=i;
int y=i*2;
int z=i*3;
for(int j=1;j<10;j++)a[j]=0;
for(int j=0;j<3;j++){
a[x%10]++;
x/=10;
}
for(int j=0;j<3;j++){
a[y%10]++;
y/=10;
}
for(int j=0;j<3;j++){
a[z%10]++;
z/=10;
}
bool bo=true;
for(int j=1;j<10;j++){
if(a[j]!=1){
bo=false;
break;
}
}
if(bo==true){
cout<<i<<" "<<i*2<<" "<<i*3<<endl;
}
}
return 0;
}