The Order of Poker

Source: Internet
Author: User

From the point of the sword


Analysis:

In three steps:

1: Sort the array

2: Find the total number of vacancies between 0 and adjacent numbers in the array

3: Compare the size of the two.

Code:

#include "stdafx.h"
#include <math.h>
#include <iostream>
using namespace std;

int compare (const void* arg1, const void* arg2)
{
	return (* (int*) arg1-* (int*) arg2);
}
BOOL Iscontinuous (int* numbers, int length)
{
	if (Numbers==null | | length<1)
		return false;
	Qsort (numbers, length, sizeof (int), compare);

	int numberofzero = 0;
	int numberofgap = 0;

	The number of 0 in the statistics array for
	(int i = 0; i<length && numbers[i]==0; i++)
		numberofzero++;
	Number of intervals in the statistics array
	int small = Numberofzero;
	int big = small+1;
	while (big < length)
	{
		//two numbers are equal, there are pairs, it cannot be CIS
		if (numbers[small] = = Numbers[big])
			return false;< C25/>numberofgap + = numbers[big]-numbers[small]-1;
		small = big;
		big++;
	}
	Return (Numberofgap>numberofzero)? False:true;
}

int _tmain (int argc, _tchar* argv[])
{
	int a[]={5,4,0,0,0,9};
	if (iscontinuous (a,6))
		cout << "is the poker order" <<endl;
	else
		cout << "non-compliant" <<endl;

	return 0;
}


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.