fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int arr[] = {1, 0, 3, 4, 0, 6, 7, 8, 9};
  7. int k = 4;
  8. int len = sizeof(arr) / sizeof(int);
  9. int product = 1;
  10. int counted = 0;
  11. int zeros = 0;
  12.  
  13. for (int i = 0; i < len; i++)
  14. {
  15. counted++;
  16.  
  17. if (arr[i] == 0)
  18. {
  19. zeros++;
  20. product = 1;
  21. }
  22.  
  23. else
  24. product *= arr[i];
  25.  
  26. if (counted >= k)
  27. {
  28. if (counted > k)
  29. {
  30. if (arr[i - k] == 0)
  31. zeros--;
  32.  
  33. else if (zeros == 0)
  34. product /= arr[i - k];
  35. }
  36.  
  37. if (zeros == 0)
  38. cout << product << endl;
  39.  
  40. else
  41. cout << 0 << endl;
  42. }
  43. }
  44.  
  45.  
  46. return 0;
  47. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
0
0
0
0
0
3024