Advertisement
vlatkovski

Olimpiski igri (училишен '17) za 7/12

Mar 9th, 2018
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int n;
  6.     cin >> n;
  7.     int a[100000] = {};
  8.     for (int i = 0; i < n; ++i) cin >> a[i];
  9.     int c = 0;
  10.     int last = 0;
  11.     for (int i = 0; i < n; ++i) {
  12.         int v = a[i];
  13.         int next = -1;
  14.         if (i+1<n) next = a[i+1];
  15. //        cout << "i:" << i << " last:" << last << " v:" << v << " next:" << next << endl;
  16.         if (v == 0) {
  17.             last = 0;
  18.         } else if (v == 3) {
  19.             if (next == 1) {
  20.                 last = 2;
  21.                 c++;
  22.             } else {
  23.                 last = 1;
  24.                 c++;
  25.             }
  26.         } else { //1, 2
  27.             if (last == v) {
  28.                 last = 0;
  29.             } else { //v != last
  30. //                if (next == 0 || next == v || next == 3) {
  31. //                    last = v;
  32. //                    c++;
  33. //                } else {
  34.                     //last = 0;
  35.                     last = v;
  36.                     c++;
  37.                 }
  38.             }
  39.         }
  40.     }
  41.     cout << c << endl;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement