#include <bits/stdc++.h>
using namespace std;
const int maks_dlugosc = 50001;
int nuty[maks_dlugosc];
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
int ilosc_nut = 0;
int obecna_nuta = 1;
int ruchy = 0;
int powinna_byc_malejaca = 0;
cin >> ilosc_nut;
for (int i = 0; i < ilosc_nut; i++) {
cin >> nuty[i];
}
if (nuty[0] > nuty[1]) {
powinna_byc_malejaca = 1;
}
if (nuty[0] < nuty[1]) {
powinna_byc_malejaca = 0;
}
if (nuty[0] == nuty[1]) {
powinna_byc_malejaca = 1;
}
while (obecna_nuta != ilosc_nut) {
if (nuty[obecna_nuta] > nuty[obecna_nuta - 1] and powinna_byc_malejaca == 1 ) {
nuty[obecna_nuta] = -1000000000;
++ruchy;
}
if (nuty[obecna_nuta] < nuty[obecna_nuta - 1] and powinna_byc_malejaca == 0) {
nuty[obecna_nuta] = 1000000000;
++ruchy;
}
if (nuty[obecna_nuta] == nuty[obecna_nuta - 1] and powinna_byc_malejaca == 1) {
nuty[obecna_nuta] = -1000000000;
++ruchy;
}
if (nuty[obecna_nuta] == nuty[obecna_nuta - 1] and powinna_byc_malejaca == 0) {
nuty[obecna_nuta] = 1000000000;
++ruchy;
}
++obecna_nuta;
if (powinna_byc_malejaca == 1) {
powinna_byc_malejaca = 0;
continue;
}
else {
powinna_byc_malejaca = 1;
}
}
cout << ruchy;
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 57 58 59 60 61 62 63 64 65 66 67 68 | #include <bits/stdc++.h> using namespace std; const int maks_dlugosc = 50001; int nuty[maks_dlugosc]; int main() { ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); int ilosc_nut = 0; int obecna_nuta = 1; int ruchy = 0; int powinna_byc_malejaca = 0; cin >> ilosc_nut; for (int i = 0; i < ilosc_nut; i++) { cin >> nuty[i]; } if (nuty[0] > nuty[1]) { powinna_byc_malejaca = 1; } if (nuty[0] < nuty[1]) { powinna_byc_malejaca = 0; } if (nuty[0] == nuty[1]) { powinna_byc_malejaca = 1; } while (obecna_nuta != ilosc_nut) { if (nuty[obecna_nuta] > nuty[obecna_nuta - 1] and powinna_byc_malejaca == 1 ) { nuty[obecna_nuta] = -1000000000; ++ruchy; } if (nuty[obecna_nuta] < nuty[obecna_nuta - 1] and powinna_byc_malejaca == 0) { nuty[obecna_nuta] = 1000000000; ++ruchy; } if (nuty[obecna_nuta] == nuty[obecna_nuta - 1] and powinna_byc_malejaca == 1) { nuty[obecna_nuta] = -1000000000; ++ruchy; } if (nuty[obecna_nuta] == nuty[obecna_nuta - 1] and powinna_byc_malejaca == 0) { nuty[obecna_nuta] = 1000000000; ++ruchy; } ++obecna_nuta; if (powinna_byc_malejaca == 1) { powinna_byc_malejaca = 0; continue; } else { powinna_byc_malejaca = 1; } } cout << ruchy; return 0; } |
English