[ create a new paste ] login | about

Link: http://codepad.org/Y9diY8Fa    [ raw code | output | fork ]

C++, pasted on Jun 27:
#include <algorithm>
#include <functional>
#include <iostream>

int MaxSequence(const int* arr, size_t size) {
  int result = 0;

  const int* last;
  for (const int* first = arr; first != arr + size; first = last) {
    last   = std::find_if(first , arr + size  , std::bind2nd(not_equal_to<int>(), *first));
    result = std::max    (result, last - first);
  }

  return result;
}

int main() {
  int arr[] = { 3, 3, 2, 3, 1, 1, 5, 3, 3, 3 };
  
  std::cout << MaxSequence(arr, sizeof(arr) / sizeof(arr[0]));
  
  return 0;
}


Output:
1
3


Create a new paste based on this one


Comments: