日常-acm-排列

  用1-9组成三个数abc,def,ghi,每个数字恰好出现一次,要求abc:def:ghi=1:2:3。按照“abc def ghi”输出所有解,每行一个解。

 1 #include <iostream>
 2 #include<algorithm>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     int x,y,z,a[10],flag=0;
 8     for(x=123;x<333;x++){
 9         flag=0;
10         y=2*x;
11         z=3*x;
12         if(y<333||y>666||z<666)
13             continue;
14         a[1]=x/100;
15         a[2]=x/10%10;
16         a[3]=x%10;
17         a[4]=y/100;
18         a[5]=y/10%10;
19         a[6]=y%10;
20         a[7]=z/100;
21         a[8]=z/10%10;
22         a[9]=z%10;
23         sort(a,a+10);
24         for(int i=1;i<10;i++){
25             if(a[i]!=i)
26                 flag=1;
27         }
28         if(flag==0)
29             cout<<x<<" "<<y<<" "<<z<<endl;
30     }
31     return 0;
32 }
原文地址:https://www.cnblogs.com/qq1353842241/p/7988366.html