The straight son of poker
Randomly draw 5 cards from poker, judging whether it is a straight, that is, the 5 cards are not continuous.
2-10 is the number itself, A is 1,j to 11,q for 12,k to 13, and the size King can be regarded as any number.
Did not find a good solution, paste my solution, see there is no better solution.
I use an array to store the input numbers, with 99 for the size of the king, and then sort them, when the period is not 99 to find the difference between the previous and the last-1 of the sum, that is, how many cards in the middle difference, and the number of kings compared.
#include <iostream>
#include <stack>
using namespace Std;
void Sortarray (int a[],int length)//bubble sort to sort the array
{
for (int i=0;i<length;i++)
{
{
for (int j=i;j<length;j++)
{
if (A[i]>a[j])
{
int temp=a[i];
A[I]=A[J];
A[j]=temp;
}
}
}
}
for (int i=0;i<length;i++)
{
cout<<a[i];
}
}
BOOL Iscontinue ()//judging whether continuous
{
int *a = new Int[5];
int Num,count=0,num99=0;//count is the number of cards, Num99 is king.
for (int i=0;i<5;i++)
{
cin>>num;
A[i]=num;
}
Sortarray (a,5);
for (int i=1;i<5;i++)
{
if (a[i]==99)
num99++;
Else
{
Count=count+a[i]-a[i-1]-1;
}
}
if (count<=num99)//If the number of bad cards is less than or equal to the number of kings consecutively, otherwise discontinuous
return true;
else return false;
}
int main (int argc, char * * argv)
{
BOOL Ret=iscontinue ();
cout<<ret;
return 0;
}
Algorithm: Playing cards of the straight son