Problem 2218 : K Poker

解法

役の定義にしたがって実装する。
実装例は以下のコード参照。

ソースコード

int n,pt[4][13],mul[10];
bool hand[4][14];

int ck()
{
	int rank[13]={0};
	rep(i,4)rep(j,13)if(hand[i][j])rank[j]++;
	
	bool royal=0,straight=0,flush=0,four=0,three=0; int two=0;
	rep(i,10)
	{
		rep(j,5)if(!rank[(i+j)%13])goto FAIL;
		if(i==9)royal=1;
		straight=1; FAIL:;
	}
	bool e[4]={0}; int s=0;
	rep(i,4)rep(j,13)if(hand[i][j])e[i]=1;
	rep(i,4)s+=e[i];
	flush=s==1;
	
	rep(i,13)
	{
		if(rank[i]==4)four=1;
		if(rank[i]==3)three=1;
		if(rank[i]==2)two++;
	}
	if(straight&&flush)return royal?8:7;
	if(four)return 6;
	if(two&&three)return 5;
	if(flush)return 4;
	if(straight)return 3;
	if(three)return 2;
	if(two==2)return 1;
	if(two)return 0;
	return 9;
}

int main()
{
	char st[256]; st['S']=0; st['C']=1; st['H']=2; st['D']=3;
	char ra[256]; for(int i=2;i<=9;i++)ra['0'+i]=i-1;
	ra['A']=0; ra['T']=9; ra['J']=10; ra['Q']=11; ra['K']=12;
	
	bool f=1;
	while(~scanf("%d",&n))
	{
		if(!f)puts(""); else f=0;
		rep(i,4)rep(j,13)scanf("%d",pt[i]+j);
		rep(i,9)scanf("%d",mul+i);
		
		rep(i,n)
		{
			rep(j,4)rep(k,13)hand[j][k]=0;
			
			int bs=0;
			rep(j,5)
			{
				char h[3]; scanf("%s",h);
				int r=ra[h[0]],s=st[h[1]];
				hand[s][r]=1; bs+=pt[s][r];
			}
			printf("%d\n",mul[ck()]*bs);
		}
	}
	return 0;
}