#include <iostream>
#include <array>
#include <string>
using namespace std;
using u16 = unsigned short;
using uu = unsigned int;
#define A 1
#define T 10
#define J 11
#define Q 12
#define K 13
enum SHAPE : u16
{
none,
C = 1 << 0,
H = 1 << 3,
D = 1 << 6,
S = 1 << 9,
};
const std::string shape_names[]
{
"none",
"clover",
"heart",
"diamond",
"spade",
};
struct CARD
{
u16 number;
SHAPE shape;
};
using hand_t = std::array< CARD, 7 >;
inline auto merge_numbers( const hand_t& hand, const int shared = 0 )
{
u16 checker = shared;
for( auto card : hand )
checker |= 1 << card.number;
return checker | ( checker & 0b10 ) << 13;
}
inline auto count_shapes( const hand_t& hand, const int shared = 0 )
{
u16 checker = shared;
for( auto card : hand )
checker += (u16)card.shape;
return checker;
}
inline auto straight_from( const hand_t& hand, const int shared = 0 )
{
u16 checker = merge_numbers( hand, shared );
const u16 top = 0b0111110000000000;
for( int count = 10; checker; checker <<= 1, --count )
if( ( checker & top ) == top ) return count;
return 0;
}
inline auto flush_index( const hand_t& hand, const int shared = 0 )
{
u16 checker = count_shapes( hand, shared );
for( int shape = 1; shape <= 4; ++shape, checker >>= 3 )
if( ( checker & 7 ) >= 5 ) return shape;
return 0;
}
hand_t hand
{ {
{ 2, D }, { 3, D }, { T, D }, { J, D }, { Q, D },
{ K, S }, { A, S },
} };
cout << straight_from( hand ) << endl;
cout << shape_names[ flush_index( hand ) ] << endl;
보관용~