Advertisement
Guest User

Problem D

a guest
Feb 18th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6.  
  7. #define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  8. #define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
  9. #define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
  10.  
  11. int main() {
  12.     optimize();
  13.     int n;
  14.     cin >> n;
  15.     int a[n];
  16.     for (int i = 0; i < n; ++i) cin >> a[i];
  17.     int cnt = 1;
  18.     bool started = 0;
  19.     for (int i = 1; i < n; ++i) {
  20.         if (a[i] == a[i - 1]) cnt++;
  21.         else {
  22.             if (started) cout << " ";
  23.             started = 1;
  24.             cout << cnt << " " << a[i - 1];
  25.             cnt = 1;
  26.         }
  27.     }
  28.     if (started) cout << " ";
  29.     started = 1;
  30.     cout << cnt << " " << a[n - 1] << endl;
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement