// test41.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "stdio.h" int a[5]={0,1,1,5,0}; void quick_sort(int * a,int low,int high){ int low1=low; int high1=high; int temp=a[low]; while(low<high){ while(low<high && a[high]>=temp) high--; a[low]=a[high]; while(low<high && a[low]<=temp) low++; a[high]=a[low]; } a[low]=temp; if(low>low1) quick_sort(a,low1,low-1); if(high1>low) quick_sort(a,low+1,high1); } bool is_OK(int * a){ int time=0; int count=0; quick_sort(a,0,4); for(int i=0;i<5;i++) if(!a[i]) time++; //计算0 总数; for(int j=time-1;j<4;j++){ if(a[j+1]==a[j]) //有相等的 对子 则返回否; return false; count+=a[j+1]-a[j]-1; //计算空缺处总数 } return (time==count); //空缺处和0值处是否一致 } int main(int argc, char* argv[]) { printf("%s/n",is_OK(a)?"OK":"not OK"); }