题解 P1008 【三连击】

· · 题解

虽然题目很水,不过试了下STL的全排列感觉桑心病狂= =

[c++]

#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int a[]={1,2,3,4,5,6,7,8,9};
    int i,j;
    for (i=1;i<=362880;i++){
        //for (j=0;j<5;j++) cout << a[j] << " ";
        if (((a[0]*100+a[1]*10+a[2])*3==(a[6]*100+a[7]*10+a[8]))&&
        ((a[0]*100+a[1]*10+a[2])*2==(a[3]*100+a[4]*10+a[5]))) {
            for (j=0;j<3;j++) cout << a[j*3] << a[j*3+1]<< a[j*3+2]<<" ";
            cout <<endl;
        }
        next_permutation(a,a+9);//STL全排列函数
    }
    return 0;
}
[/c++]