#include <iostream>
#include <string>
#include <algorithm>
#include <string>
#define n 5
using namespace std;
struct Card
{
string str;
char color;
char value;
int order;
int col_order;
} card[100];
bool cmp(Card a, Card b)
{
if (a.order != b.order)
return a.order < b.order;
else return a.col_order < b.col_order;
}
bool sort_cmp (Card a, Card b)
{
if (a.order != b.order)
return a.order < b.order;
else return a.col_order < b.col_order;
}
bool compare (Card a, Card b)
{
if (a.order > b.order)
return true;
if (a.order < b.order)
return false;
if (a.col_order > b.col_order)
return true;
return false;
}
int main()
{
int T;
cin >> T;
for (int j = 1; j <= T; j++) {
for (int i = 0; i < n; i++)
{
cin >> card[i].str;
int len = card[i].str.length();
card[i].color = card[i].str[len - 1];
if (len == 3) {
card[i].order = 10;
} else {
card[i].value = card[i].str[0];
if (card[i].value == 'A')
card[i].order = 1;
else if (card[i].value == 'J')
card[i].order = 11;
else if (card[i].value == 'Q')
card[i].order = 12;
else if (card[i].value == 'K')
card[i].order = 13;
else
card[i].order = card[i].value - '0';
}
if (card[i].color == 'C')
card[i].col_order = 1;
else if (card[i].color == 'D')
card[i].col_order = 2;
else if (card[i].color == 'H')
card[i].col_order = 3;
else
card[i].col_order = 4;
}
sort(card, card+n, sort_cmp);
do
{
if (card[0].color == card[1].color)
{
int realValue, temp, min;
realValue = card[0].order;
temp = card[1].order;
int position = 1;
int count = 1;
min = card[2].order;
count++;
if (card[3].order < min) {
min = card[3].order;
position = count;
}
count++;
if (card[4].order < min) {
min = card[4].order;
position = count;
}
temp += position;
if (position == 1) {
if (compare(card[3], card[4]))
temp += 3;
} else if (position == 2) {
if (compare(card[2], card[4]))
temp += 3;
} else {
if (compare(card[2], card[3]))
temp += 3;
}
if (temp % 13 == realValue)
{
cout << "Problem " << j << ": ";
for (int i = 0; i < n - 1; i++) {
if (card[i].order == 10)
cout << card[i].order << card[i].color << " ";
else
cout << card[i].value << card[i].color << " ";
}
if (card[n - 1].order == 10)
cout << card[n - 1].order << card[n - 1].color <<endl;
else
cout << card[n - 1].value << card[n - 1].color << endl;
break;
}
}
} while (next_permutation(card, card + n, cmp));
}
return 0;
}
1018. A Card Trick
最新推荐文章于 2021-01-18 22:55:10 发布