Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <Windows.h>
  4.  
  5. int main() {
  6.     int n;
  7.     bool nowBigger;
  8.  
  9.     std::cin >> n;
  10.  
  11.     int *a = new int[n];
  12.    
  13.     int c = 0;
  14.  
  15.     for (int i = 1; i <= n; i++) {
  16.         std::cin >> a[i];
  17.         if (a[i] <= 0) {
  18.             return 0;
  19.         }
  20.  
  21.         if (a[2] > a[1]) {
  22.             nowBigger = true;
  23.         }
  24.         else {
  25.             nowBigger = false;
  26.         }
  27.     }
  28.  
  29.     for (int i = 1; i <= n; i++) {
  30.         if (a[i] == 0 || a[i + 1] == 0) {
  31.             i++;
  32.         }
  33.  
  34.         if (a[i] == a[i + 1]) {
  35.             a[i] = 0;
  36.         }
  37.  
  38.  
  39.         else if (a[i] > a[i + 1]) { //i + 1 is smaller
  40.             if (i + 1 < n) {
  41.                 if (a[i + 1] > a[i + 2] && a[i + 1] < a[i + 3]) {
  42.                     a[i + 2] = 0;
  43.                 }
  44.                 else if (a[i + 1] < a[i + 2] && a[i + 2] < a[i + 3]) {
  45.                     a[i + 1] = 0;
  46.                 }
  47.             }
  48.             nowBigger = true;
  49.         }
  50.         else if (a[i] < a[i + 1] && nowBigger == true) {
  51.             if (a[i + 1] < a[i + 2]) {
  52.                 a[i] = 0;
  53.             }
  54.             nowBigger = false;
  55.         }
  56.     }
  57.  
  58.     for (int i = 1; i <= n; i++) {
  59.         c += a[i];
  60.         std::cout << a[i] << std::endl;
  61.     }
  62.  
  63.     std::cout << c;
  64.  
  65.     system("pause");
  66.  
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement