题目挺水,只有“1 2 4”,”1 2 6“,”1 3 6“这三种情况符合。所以就简单多了。
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<deque>
#include<functional>
#include<iterator>
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#define CPY(A, B) memcpy(A, B, sizeof(A))
typedef long long LL;
typedef unsigned long long uLL;
const int MOD = int (1e9) + 7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double OO = 1e20;
const double PI = acos (-1.0);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
int main() {
int n,k,a[7]= {0};
while (cin>>n) {
bool f=true;
for (int i=0; i<n; i++) {
scanf ("%d",&k);
if (k==5||k==7) {f=false;}//5,7,直接排除
a[k]++;
}
if (f&&a[1]==a[2]+a[3]&&a[1]==a[4]+a[6]&&a[2]>=a[4]) {
for (int i=0; i<a[4]; i++) {
printf ("1 2 4\n");
a[2]--;a[1]--;//减去这部分2,剩余2的数量就是”1 2 6“的数量
}
for (int j=0; j<a[2]; j++) {
printf ("1 2 6\n");
a[1]--;
}
for (int k=0; k<a[1]; k++) {
printf ("1 3 6\n");
}
} else {cout<<"-1\n";}
}
return 0;
}