C
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
struct s_hands
{
int suit;
int num;
int cnt;
};
struct s_num
{
char n[16][4];
};
struct s_hands check_st_cnt(const char * input, const struct s_num c_num )
{
int i = 0;
int cnt = 0;
struct s_hands hd = {0};
for( i = 0; strcmp(c_num.n[i],"\0") != 0; i++ )
{
cnt++;
if( strstr( input, c_num.n[i] ) == NULL )
cnt = 0;
if( hd.cnt < cnt )
{
hd.cnt = cnt;
hd.num = i;
}
}
return hd;
}
struct s_hands check_fl_cnt(const char * input, const char c_suit[][3])
{
int i = 0;
int j = 0;
int cnt = 0;
struct s_hands hd = {0};
for( i = 0; strcmp(c_suit[i], "\0") != 0; i++ )
{
cnt = 0;
for( j = 0; j < strlen(input); j++ )
if( input[j] == c_suit[i][0] ) cnt++;
if( hd.cnt < cnt )
{
hd.suit = i;
hd.cnt = cnt;
}
}
return hd;
}
void test (const char * input, const char * ans)
{
enum e_hands { ST, FL, SF };
const char c_suit[][3] = {"a","s","h","d","c","\0"};
const struct s_num c_num = { {"0","A","2","3","4","5","6","7","8","9","10","J","Q","K","A","\0"} };
struct s_num num = {0};
char str[4] = "-";
int i = 0;
struct s_hands hd[3] = {0};
hd[ST] = check_st_cnt(input, c_num );
hd[FL] = check_fl_cnt(input, c_suit);
num = c_num;
for( i = 0; strcmp(c_num.n[i],"\0") != 0; i++ )
strcat(num.n[i], c_suit[hd[FL].suit]);
hd[SF] = check_st_cnt(input, num );
//printf("num=%d, suit=%d, cnt=%d\n", hd[0].num, hd[0].suit, hd[0].cnt);
//printf("num=%d, suit=%d, cnt=%d\n", hd[1].num, hd[1].suit, hd[1].cnt);
//printf("num=%d, suit=%d, cnt=%d\n", hd[2].num, hd[2].suit, hd[2].cnt);
strcpy(str, (hd[SF].cnt == 5 && hd[SF].num == 14) ? "RF"
: (hd[SF].cnt == 5) ? "SF"
: (hd[FL].cnt == 5) ? "FL"
: (hd[ST].cnt == 5) ? "ST"
: (hd[SF].cnt == 4) ? "4SF"
: (hd[FL].cnt == 4) ? "4F"
: (hd[ST].cnt == 4) ? "4S"
: "-" );
printf("%s:%s\n", (strcmp(ans,str) == 0) ? "ooooo GOOD ooooo": "xxxxx BAD xxxxx", str);
}
int main (void)
{
/*0*/ test( "Qs9s3dJd10h", "4S" );
/*1*/ test( "KdAdJd10dQd", "RF" );
/*2*/ test( "QhJhKhAh10h", "RF" );
/*3*/ test( "10dAdJsQdKd", "ST" );
/*4*/ test( "Kd10dAdJd3d", "FL" );
/*5*/ test( "4d3d2dAd5d", "SF" );
/*6*/ test( "5d5d2d3dAd", "FL" );
/*7*/ test( "4d2sAd5d3d", "ST" );
/*8*/ test( "As10dJdQdKd", "ST" );
/*9*/ test( "10d10dQdAsJd", "4F" );
/*10*/ test( "AcJd10dQdKd", "ST" );
/*11*/ test( "Kd2sJdAdQd", "4SF" );
/*12*/ test( "JdAdQcKd2s", "4S" );
/*13*/ test( "KdAdKdJd2s", "4F" );
/*14*/ test( "As2dKdQdJd", "4F" );
/*15*/ test( "AsKdQd2dJh", "4S" );
/*16*/ test( "QhAd2s3dKd", "-" );
/*17*/ test( "Ad4dKh3s2d", "4S" );
/*18*/ test( "3d2dAh5d4s", "ST" );
/*19*/ test( "QcKdAs2dJd", "4S" );
/*20*/ test( "2dQcJdAs10d", "-" );
/*21*/ test( "4d7d5s3c2d", "4S" );
/*22*/ test( "7d5s4dAd3c", "-" );
/*23*/ test( "3s8s10sQs6s", "FL" );
/*24*/ test( "6hAh3h2h8h", "FL" );
/*25*/ test( "3h4hJh9hQh", "FL" );
/*26*/ test( "3s6s5s2sQs", "FL" );
/*27*/ test( "9d3cKdQc2c", "-" );
/*28*/ test( "5sKs7hQcKh", "-" );
/*29*/ test( "Ad6d7h7c9h", "-" );
/*30*/ test( "10h4cAh6s10c", "-" );
/*31*/ test( "9sKsJcQs10d", "ST" );
/*32*/ test( "5d3c2cAs4c", "ST" );
/*33*/ test( "KcQs9c10sJs", "ST" );
/*34*/ test( "9d8s10hJdQd", "ST" );
/*35*/ test( "6c5s10h7d4c", "4S" );
/*36*/ test( "QhJcKsAh8c", "4S" );
/*37*/ test( "JsQc3h10cKs", "4S" );
/*38*/ test( "10c9h7hAd8d", "4S" );
/*39*/ test( "3d4dKd8d5c", "4F" );
/*40*/ test( "10h3hQh9h2s", "4F" );
/*41*/ test( "Qh5h7h9h6c", "4F" );
/*42*/ test( "6s8s7s3sKc", "4F" );
/*43*/ test( "10h8h9hJhQh", "SF" );
/*44*/ test( "10h9hQhKhJh", "SF" );
/*45*/ test( "6d4d7d5d3d", "SF" );
/*46*/ test( "6h9h7h5h8h", "SF" );
/*47*/ test( "Ac6s4s3s5s", "4SF" );
/*48*/ test( "3c9d2c5c4c", "4SF" );
/*49*/ test( "Kh2sQh10hJh", "4SF" );
/*50*/ test( "4h5h2h3h4s", "4SF" );
/*51*/ test( "Js10sAsQsKs", "RF" );
/*52*/ test( "10dKdQdAdJd", "RF" );
return 0;
}