ZCC loves straight flush

After losing all his chips when playing Texas Hold'em with Fsygd on the way to ZJOI2015, ZCC has just learned a black technology. Now ZCC is able to change all cards as he wants during the game. ZCC wants to get a Straight Flush by changing as few cards as possible. 

We call a five-card hand a Straight Flush when all five cards are consecutive and of the same suit. You are given a five-card hand. Please tell ZCC how many cards must be changed so as to get a Straight Flush. 
   
Cards are represented by a letter('A', 'B', 'C', 'D') which denotes the suit and a number('1', '2',  , '13') which denotes the rank. 
   
Note that number '1' represents ace which is the largest actually. "1 2 3 4 5" and "10 11 12 13 1" are both considered to be consecutive while "11 12 13 1 2" is not.

Input

First line contains a single integer  T(T=1000)  which denotes the number of test cases. 
For each test case, there are five short strings which denote the cards in a single line. It's guaranteed that all five cards are different.

Output

For each test case, output a single line which is the answer.

Sample Input

3
A1 A2 A3 A4 A5
A1 A2 A3 A4 C5
A9 A10 C11 C12 C13

Sample Output

0
1
2


题意:"同花顺”,给你五张扑克,A,B,C,D为类型,就像梅花方片,1234为数字,让你找如果让这五张牌变成同花顺至少需要换掉几张,其中1可以当“A”(尖)用,就是1,2,3,4,5和10,11,12,13,1都是顺子;

思路是找给的这五张牌中,能构成同花顺的最大序列长度是多少,最后用5减max即可。

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int a[4][50],lenn[4];
int main()
{
	int t,n,m,i,len,max,j,k;
	char ch[50];
	scanf("%d",&t);
	getchar();
	while(t--)
	{
		max=0;
		memset(lenn,0,sizeof(lenn));
		gets(ch);
		//printf("%s\n",ch);
		len=strlen(ch);
		for(i=0;i<len;i++)
		{
			if(ch[i]>='A'&&ch[i]<='D')
			{
				
				if(ch[i+2]>='0'&&ch[i+2]<='9')
				{
					a[ch[i]-'A'][lenn[ch[i]-'A']++]=(ch[i+1]-'0')*10+ch[i+2]-'0';
					i+=3;
				}
				else
				{
					a[ch[i]-'A'][lenn[ch[i]-'A']++]=ch[i+1]-'0';
					i+=2;
				}
			}
		}
		for(i=0;i<4;i++)
		sort(a[i],a[i]+lenn[i]);
		for(i=0;i<4;i++)
		{
			if(a[i][0]==1)
			a[i][lenn[i]++]=14;
			for(j=0;j<lenn[i];j++)
			{
				k=j+1;
				while(k<lenn[i]&&a[i][k]<(a[i][j]+5))
				{
					k++;
				}
				if((k-j)>max)
				{
					max=k-j;
				}
				
			}
		}
		printf("%d\n",5-max);
	}
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值