Solved the problem according to the following algorithm. We have a maximum and current variable. We iterate over the array if the element is found = 0; then we increase the value of the counter by one. Otherwise, if the current sequence is larger than the maximum, then we assign the maximum current one. And reset the counter. The program just shows me the number of elements from 0. What I did wrong.

#include <iostream> using namespace std; int main() { const int size = 11; int arr[size] = {100, 1, 0, 36, 0000, 74, 00, 666, 32, 000000, 17}; int temp = 0; int max = 0; for (int i = 0; i < size; ++i) { if(arr[i] == 0) { ++temp; } else { if(temp > max) { max = temp; } } } cout << "Max is :" << max << endl; return 0; } 
  • one
    if you look at this line if (arr [i] == 0) then for a program that 000000, that 00 is still zero, so this check does not count you how many zeros are written, but whether it is just zero by mathematical to the standards. - Comfmore

4 answers 4

  1. Why do you need numbers like 0000? The sequence of zeros, as I understand it, is {..., 0, 0, 0, ...};
  2. You do not have zero temp at the end of the sequence.
  3. Plus, you need code to handle the queue, which will be at the end of the array (when the second condition is not met).

    A numeric literal starting from zero is a number in an octal representation, such as a number starting with 0x, a number in hexadecimal. For example, 08 cannot be written. For example, 0xA is 10, and 010 is 8.

      It is necessary to reset temp when the chain of zeros ends.

        else { if(temp > max) { max = temp; } temp = 0; // здесь обнулить забыли } 

        you have temp is not reset, he himself once made such a mistake, speaking at the Olympiad and paid very much for it