Algorithm: Playing cards of the straight son

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.