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;
}