Ciao a tutti non riesco a passare l’ultimo testcase, non capisco dove sbaglio:
#include <bits/stdc++.h>
#define ve vector
#define pb push_back
using namespace std;
struct card {
int x;
char s;
};
int main() {
//ifstream cin("input.txt");
//ofstream cout("output.txt");
card mano[3];
card tav[4];
int setteBello = 0;
for(int i = 0; i < 3; ++i) {
cin >> mano[i].x >> mano[i].s;
if(mano[i].x == 7 && mano[i].s == 'G') setteBello = 1;
}
for(int i = 0; i < 4; ++i) {
cin >> tav[i].x >> tav[i].s;
if(tav[i].x == 7 && tav[i].s == 'G') setteBello = 2;
}
if(setteBello == 1) {
for(int i = 0; i < 4; ++i) {
if(tav[i].x == 7) {
cout << "7G 7" << tav[i].s;
return 0;
}
}
}
else if(setteBello == 2) {
for(int i = 0; i < 3; ++i) {
if(mano[i].x == 7) {
cout << "7G 7" << mano[i].s;
return 0;
}
}
}
for(int i = 0; i < 3; ++i) {
int sum = 0;
for(int j = 0; j < 4; ++j) {
sum += tav[j].x;
}
if(mano[i].x == sum) {
cout << mano[i].x << mano[i].s;
for(int u = 0; u < 4; ++u) cout << ' ' << tav[u].x << tav[u].s;
return 0;
}
}
for(int i = 0; i < 3; ++i) {
if(mano[i].x == 7) {
for(int j = 0; j < 4; ++j) {
if(tav[j].x == 7) {
cout << mano[i].x << mano[i].s << ' ' << tav[j].x << tav[j].s;
return 0;
}
}
}
}
ve<card> ans;
for(int t = 0; t < 3; ++t) {
for(int i = 1; i < 16; ++i) {
int sum = 0;
ve<card> cr;
for(int j = 0; j < 4; ++j) {
if(i & (1 << j)) {
sum += tav[j].x;
cr.pb({tav[j].x, tav[j].s});
}
}
if(sum == mano[t].x) {
cr.pb({mano[t].x, mano[t].s});
if(cr.size() > ans.size()) {
ans.clear();
for(auto h : cr) ans.pb(h);
}
}
}
}
for(auto i : ans) cout << i.x << i.s << ' ';
return 0;
}