#include <bits/stdc++.h>
using namespace std;
int t1[50007]; // liczby
int rz[50007]; // zmiana liczb
int sign(int a) {
if (a > 0) return 1;
else if (a < 0) return -1;
else return 0;
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int n; cin >> n;
cin >> t1[0];
int licz = 0;
for (int i = 1; i < n; ++i) {
cin >> t1[i];
rz[i] = t1[i] - t1[i-1];
if (sign(rz[i]) == sign(rz[i-1]) || rz[i] == 0) ++licz;
}
cout << ceil(double(licz)/2);
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 | #include <bits/stdc++.h> using namespace std; int t1[50007]; // liczby int rz[50007]; // zmiana liczb int sign(int a) { if (a > 0) return 1; else if (a < 0) return -1; else return 0; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n; cin >> n; cin >> t1[0]; int licz = 0; for (int i = 1; i < n; ++i) { cin >> t1[i]; rz[i] = t1[i] - t1[i-1]; if (sign(rz[i]) == sign(rz[i-1]) || rz[i] == 0) ++licz; } cout << ceil(double(licz)/2); return 0; } |
English