Advertisement
Josif_tepe

Untitled

Mar 9th, 2021
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n;
  8.     cin>>n;
  9.     int niza[n];
  10.     for(int i=0;i<n;i++)
  11.     {
  12.         cin>>niza[i];
  13.     }
  14.  
  15.     int broj=0;
  16.     int prev_zero = -1;
  17.     for(int i=0;i<n;i++)
  18.     {
  19.         if(niza[i] == 0) {
  20.             broj += (i - prev_zero) * (n - i);
  21.             prev_zero = i;
  22.         }
  23.     }
  24.     cout << broj << endl;
  25.     return 0;
  26. }
  27. //4, 5, 0, 1, 2
  28. // prev_zero = -1
  29. // i - prev_zoro
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement