DESCRIPTION
Our friend Quailty is playing a card game with his friend Skywalkert.
The game is played with a standard 52-card deck, with 13 cards from each of the four suits (hearts, spades, clubs, and diamonds). The cards are ranked as A, K, Q, J, 10, 9, 8, 7, 6, 5, 4, 3, 2, with the ace having the highest rank and 2 the lowest. There is also a predetermined trump suit (H = hearts, S = spades, C = clubs, D = diamonds).
The game has several rounds. In the first round, Quailty starts by showing one of the cards he has and then Skywalkert follows. Remember that before Skywalkert showing a card, he can see the card Quailty has shown and choose the card he wants to show. At the end of each round, the one who has shown the card with the highest rank of all the showed cards will win this round (if the two cards have the same rank, the one who starts this round wins) and get the same score as the number written on the card with the highest rank of all the showed cards. Here we consider J as 11, Q as 12, K as 13 and A as 1. Then these two cards will be thrown away and the winner of this round starts the next round, until all the cards have been thrown away.
For simplicity, at the beginning of the game, each of them has only two cards and they can see all the cards. You need to calculate the maximum of the total score of Quailty minus the total score of Skywalkert, denoted by S
. Both of them, of course, play optimally, which means that Quailty will spare no effort to maximize S
while Skywalkert will try to minimize it.
INPUT
The first line contains an integer T (1≤T≤10000)
, which is the number of test cases. For each test case, the two lines each contain a space-separated list of two cards. A card is represented as a string XY, where X is one of A, K, Q, J, T (representing 10), 9, 8, 7, 6, 5, 4, 3, 2, and Y
is the suit (one of H, S, C, D).
It is guaranteed that no card appears twice for each test case.
OUTPUT
For each test case, output ine one line an integer, which is the answer.
SAMPLE INPUT
2
AH 2S
3C 4D
2H 5S
3C 4D
SAMPLE OUTPUT
-3
1
英语太渣啊,弄错题意啊!
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int init(char c){
if(c == 'J') return 11;
else if(c == 'Q') return 12;
else if(c == 'K') return 13;
else if(c == 'A') return 14;
else if(c == 'T') return 10;
else return (c-'0');
}
int maxi(int a,int b,int j){
int y = max(a,b);
if(a>b){
if(y == 14) return 1;
else return y;
}
else if(a < b){
if(y == 14) return -1;
else return -y;
}
else if(a == b){
if(j == 0){
if(y == 14) return 1;
else return y;
}
else {
if(y == 14) return -1;
else return -y;
}
}
}
int main(){
//freopen("in.txt","r",stdin);
int t;
scanf("%d",&t);
string s1,s2,s3,s4;
while(t--){
cin>>s1>>s2>>s3>>s4;
int x1,x2,y1,y2;
x1 = init(s1[0]);
x2 = init(s2[0]);
y1 = init(s3[0]);
y2 = init(s4[0]);
//cout<<x1<<" "<<x2<<" "<<y1<<" "<<y2<<endl;
int sum1 = 0,sum2 = 0,sum3 = 0,sum4 = 0;
int ans1 = maxi(x1,y1,0);
if(ans1 > 0) sum1 = ans1 + maxi(x2,y2,0);
else sum1 = ans1 + maxi(x2,y2,1);
int ans2 = maxi(x1,y2,0);
if(ans2 > 0) sum2 = ans2 + maxi(x2,y1,0);
else sum2 = ans2 + maxi(x2,y1,1);
int k1 = min(sum1,sum2);
int ans3 = maxi(x2,y1,0);
if(ans3 > 0) sum3 += ans3 + maxi(x1,y2,0);
else sum3 = ans3 + maxi(x1,y2,1);
int ans4 = maxi(x2,y2,0);
if(ans4 > 0) sum4 = ans4+maxi(x1,y1,0);
else sum4 = ans4+maxi(x1,y1,1);
int k2 = min(sum3,sum4);
// cout<<sum1<<" "<<sum2<<" "<<sum3<<" "<<sum4<<endl;
cout<<max(k1,k2)<<"\n";
}
return 0;
}