zoukankan      html  css  js  c++  java
  • 剑指offer-面试题61-扑克牌中的顺子-数组

    /*
    题目:
    	从扑克牌中随机抽取n个数字,判断他们是否连续,扑克牌从A~K,大小王可代替任意数字。
    */
    #include<iostream>
    #include<cstdlib>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<deque>
    #include<cmath>
    
    using namespace std;
    
    int compare(const void* arg1, const void* arg2){
        return *(int*)arg1 - *(int*)arg2;
    }
    
    bool isContinuous(int numbers[],int length){
    
        qsort(numbers,length,sizeof(int),compare);
        int Count = 0;
        for(int i = 0; i < length; i++){
            if(numbers[i] == 0){
                Count++;
            }else{
                break;
            }
        }
        int small  = Count;
        int big = small + 1;
        int gap = 0;
        while(big < length){
            if(numbers[small] == numbers[big]){
                return false;
            }else{
                gap += (numbers[big] - numbers[small] - 1);
            }
            small++;
            big++;
        }
    
        return gap > Count ? false : true;
    }
    
    int main()
    {
        int a[] = {0,2,4,7,0};
        cout<<isContinuous(a,5);
    
    }
    

       

  • 相关阅读:
    DELPHI美化界面
    WebSevice相关
    Hotmail邮件接收
    DHTMLEdit
    Eclipse 基础
    POP3相关
    DELPHI中GIF的使用
    javaaop
    RAD Studio 2010 启动报错"displayNotification: 内存不够" 解决办法
    编程之道
  • 原文地址:https://www.cnblogs.com/buaaZhhx/p/12116565.html
Copyright © 2011-2022 走看看