Advertisement
Semior001

C task contest 8

Jul 26th, 2016
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4.     int n,i;
  5.     bool a[101] = {false};
  6.     int first_para = -1;
  7.     cin >> n;
  8.     int last_para = n-1;
  9.     cin >> a[0];
  10.     for(i = 0; i < n; i++){
  11.         cin >> a[i];
  12.         if(a[i] && first_para<0)
  13.             first_para = i;
  14.     }
  15.     while(!a[last_para]){
  16.         last_para--;
  17.     }
  18.     cout << first_para << endl;
  19.     cout << last_para << endl;
  20.     int result = 0;
  21.     int cnt = 0;
  22.     for(i = first_para; i <= last_para; i++){
  23.         if(!a[i] && cnt!=0){
  24.             cnt++;
  25.         }else{
  26.             if(cnt>1){
  27.                 result-=cnt;
  28.                 cnt = 0;
  29.             }
  30.         }
  31.         result++;
  32.     }
  33.     cout << result << endl;
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement