Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <Windows.h>
- int main() {
- int n;
- bool nowBigger;
- std::cin >> n;
- int *a = new int[n];
- int c = 0;
- for (int i = 1; i <= n; i++) {
- std::cin >> a[i];
- if (a[i] <= 0) {
- return 0;
- }
- if (a[2] > a[1]) {
- nowBigger = true;
- }
- else {
- nowBigger = false;
- }
- }
- for (int i = 1; i <= n; i++) {
- if (a[i] == 0 || a[i + 1] == 0) {
- i++;
- }
- if (a[i] == a[i + 1]) {
- a[i] = 0;
- }
- else if (a[i] > a[i + 1]) { //i + 1 is smaller
- if (i + 1 < n) {
- if (a[i + 1] > a[i + 2] && a[i + 1] < a[i + 3]) {
- a[i + 2] = 0;
- }
- else if (a[i + 1] < a[i + 2] && a[i + 2] < a[i + 3]) {
- a[i + 1] = 0;
- }
- }
- nowBigger = true;
- }
- else if (a[i] < a[i + 1] && nowBigger == true) {
- if (a[i + 1] < a[i + 2]) {
- a[i] = 0;
- }
- nowBigger = false;
- }
- }
- for (int i = 1; i <= n; i++) {
- c += a[i];
- std::cout << a[i] << std::endl;
- }
- std::cout << c;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement