Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <algorithm>
- #include <string.h>
- using namespace std;
- char val[] = {'1','2','3','4','5',
- '6','7','8','9','T','J','Q','K'};
- char suit[] = {'H', 'C', 'D', 'S'};
- struct card {
- int v,s;
- bool operator==(card& a) {
- return this->s==a.s && this->v==a.v;
- }
- };
- int t;
- card cs[4];
- void read(card& a) {
- char tmp[5];
- scanf(" %s", tmp);
- for (int i=0; i<13; i++)
- if (tmp[0]==val[i])
- a.v=i;
- for (int i=0; i<4; i++)
- if (tmp[1]==suit[i])
- a.s=i;
- }
- bool cmp(card a, card b) {
- if (a.s==b.s)
- return a.v<b.v;
- return a.s<b.s;
- }
- int compare() {
- card ord[3];
- int p[3] = {0,1,2};
- int cnt=1;
- for (int i=0; i<3; i++)
- ord[i]=cs[i+1];
- sort(ord,ord+3,cmp);
- do {
- if (cs[1]==ord[p[0]] &&
- cs[2]==ord[p[1]] &&
- cs[3]==ord[p[2]])
- return cnt;
- cnt++;
- } while (next_permutation(p,p+3));
- return cnt;
- }
- int main() {
- scanf("%d", &t);
- while (t--) {
- for (int i=0; i<4; i++)
- read(cs[i]);
- int vC = (cs[0].v+compare())%13;
- printf("%c%c\n", val[vC],suit[cs[0].s]);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment