#include<iostream> #include<vector> using namespace std; int main() { int wDol=0; int wGore=0; int n; int a; vector<int> dane; cin >> n; for (int i = 0; i < n; i++) { cin >> a; dane.push_back(a); } int stan; int stan_r; stan = 1; for (int i = 1; i < n; i++) { if (dane[i - 1] > dane[i]) stan_r = 1; else if (dane[i - 1] < dane[i]) stan_r = 0; else stan_r = -1; if (stan_r != stan) { wDol++; i++; } stan = 1 - stan; } stan = 0; for (int i = 1; i < n; i++) { if (dane[i - 1] > dane[i]) stan_r = 1; else if (dane[i - 1] < dane[i]) stan_r = 0; else stan_r = -1; if (stan_r != stan) { wGore++; i++; } stan = 1 - stan; } if (wDol < wGore) cout << wDol; else cout << wGore; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | #include<iostream> #include<vector> using namespace std; int main() { int wDol=0; int wGore=0; int n; int a; vector<int> dane; cin >> n; for (int i = 0; i < n; i++) { cin >> a; dane.push_back(a); } int stan; int stan_r; stan = 1; for (int i = 1; i < n; i++) { if (dane[i - 1] > dane[i]) stan_r = 1; else if (dane[i - 1] < dane[i]) stan_r = 0; else stan_r = -1; if (stan_r != stan) { wDol++; i++; } stan = 1 - stan; } stan = 0; for (int i = 1; i < n; i++) { if (dane[i - 1] > dane[i]) stan_r = 1; else if (dane[i - 1] < dane[i]) stan_r = 0; else stan_r = -1; if (stan_r != stan) { wGore++; i++; } stan = 1 - stan; } if (wDol < wGore) cout << wDol; else cout << wGore; return 0; } |