用1,2,3,…,9组成3个三位数abc,def和ghi,每个数字恰好使用一次,要求abc:def:ghi=1:2:3. 输出所有解,每行一个解
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3+10;
int st[10];
bool cnt(int n){
while(n){
st[n%10]++;
if(st[n%10]>1)return false;
n/=10;
}
return true;
}
int main(){
int a,b,c;
for(int i=100;i<333;i++){
a=i,b=2*i,c=3*i;
if(cnt(a)&&cnt(b)&&cnt(c))printf("%d %d %d\n",a,b,c);
memset(st,0,sizeof(st));
}
return 0;
}