Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5. int main()
  6. {
  7. int N, l, d, i, j, count=1;
  8. int a[2020];
  9. bool b = false;
  10. cin >> N;
  11. d = N ;
  12. for (i = 0; i < 2020; i++)
  13. a[i] = -1;
  14.  
  15. for (i = 0; i < N; i++){
  16. cin >> a[i];
  17. }
  18.  
  19. for (i = 0; i < N; i++)
  20. if (a[i] == a[i+1]) {
  21. count++;
  22. if (count > 2) j = i;
  23. }
  24. else if (count > 2) {
  25. b = true;
  26. break;
  27. }
  28. else {
  29. count = 1;
  30. }
  31. while (b && N>0){
  32. for (i=j - count + 2; i < N - count ; i++)
  33. a[i] = a[i+count];
  34. N = N-count;
  35. a[N] = -1;
  36. count = 1;
  37.  
  38. for (i = 0; i < N; i++)
  39. if (a[i] == a[i+1]) {
  40. count++;
  41. if (count > 2) j = i;
  42. }
  43. else if (count > 2) {
  44. b = true;
  45. break;
  46. }
  47. else {
  48. count = 1;
  49. b = false;
  50. }
  51. }
  52. cout << d - N;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement