using namespace std;
struct Card
{
int rank, suit;
public:
Card(void) {
}
Card(char _rank, char _suit) {
rank = string("23456789TJQKA").find(_rank);
suit = string("CDHS").find(_suit);
}
};
pair<int,int> evaluate(Card cards[5])
{
int freq[13] = { 0 };
for(int i = 0; i < 5; i++)
freq[cards[i].rank]++;
for(int i = 0; i < 5; i++) {
for(int j = i; j > 0; j--) {
int r0 = cards[j - 0].rank;
int r1 = cards[j - 1].rank;
if(make_pair(freq[r1], r1) > make_pair(freq[r0], r0)) { break; }
swap(cards[j - 0], cards[j - 1]);
}
}
int sign1 = 0;
int sign2 = 0;
bool flush = true;
for(int i = 0; i < 5; i++) {
sign1 = sign1 * 16 + freq[cards[i].rank];
sign2 = sign2 * 16 + cards[i].rank;
flush = flush && (cards[0].suit == cards[i].suit);
}
if(sign1 == 0x11111) {
// (sign2 == 0xC3210) --> ace-low straight
bool strgt = (cards[0].rank - cards[4].rank == 4) || (sign2 == 0xC3210);
if(flush) { sign1 += 0x22210; }
if(strgt) { sign1 += 0x22201; }
}
return make_pair(sign1, sign2);
}
// sign1 == 0x55555 : five of a kind
// sign1 == 0x55522 : straight flush (royal flush if sign2 == 0xCBA98)
// sign1 == 0x44441 : four of a kind
// sign1 == 0x33322 : full house
// sign1 == 0x33321 : flush
// sign1 == 0x33312 : straight
// sign1 == 0x33311 : three of a kind
// sign1 == 0x22221 : two pairs
// sign1 == 0x22111 : one pair
// sign1 == 0x11111 : high card
/*
------------------------------------------------------------------------------
Copyright (C) 2008 Yusuke Izumi
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
------------------------------------------------------------------------------
*/