cpp code debugging, debugging the code of playing cards

 

 

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

 
class Solution {
public:
    bool IsContinuous( vector<int> numbers ) {
        int length = numbers.size();
        if(length <= 0)
            return false;
        //sort(numbers,numbers+length);
        sort(numbers.begin(),numbers.end());
        int count = 0;
        for(int i = 0;i < length;i++){
            if(numbers[i] == 0)
                count++;
        }
        int diff = 0;
        for(int i = count;i < length - 1;i++){
            diff = numbers[i+1] - numbers[i] - 1;
            cout << numbers[i+1] << " "<< numbers[i] << " " << diff << endl;
        }
        // cout << diff << endl;
        // cout << count << endl;
        return diff <= count ? true : false;
    }
};


intmain ()
{
   int array[5] = {0,3,1,6,4};
   vector<int> iv(array, array+5);
   Solution a;
   cout << a.IsContinuous(iv) << endl;

   return 0;
}

1. Use vector to include<vector>

2. Learn to use an array to initialize the vector, the array uses { } not [ ]

3. The sort function should include <algorithm>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324642266&siteId=291194637