Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main()
- {
- int N, l, d, i, j, count=1;
- int a[2020];
- bool b = false;
- cin >> N;
- d = N ;
- for (i = 0; i < 2020; i++)
- a[i] = -1;
- for (i = 0; i < N; i++){
- cin >> a[i];
- }
- for (i = 0; i < N; i++)
- if (a[i] == a[i+1]) {
- count++;
- if (count > 2) j = i;
- }
- else if (count > 2) {
- b = true;
- break;
- }
- else {
- count = 1;
- }
- while (b && N>0){
- for (i=j - count + 2; i < N - count ; i++)
- a[i] = a[i+count];
- N = N-count;
- a[N] = -1;
- count = 1;
- for (i = 0; i < N; i++)
- if (a[i] == a[i+1]) {
- count++;
- if (count > 2) j = i;
- }
- else if (count > 2) {
- b = true;
- break;
- }
- else {
- count = 1;
- b = false;
- }
- }
- cout << d - N;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement