/*
* orn.ccp
*
* Created on: Dec 13, 2022
* Author: A.Mulawa
*/
#include <iostream>
#include <string>
#include <limits.h>
int main(int argc, char **argv) {
int k;
std::cin >> k;
bool up = false;
int t0;
std::cin >> t0;
int t1;
std::cin >> t1;
int res = 0;
if (t0 > t1)
{
up = true;
}
else if (t0 == t1) {
res ++;
t1 = INT_MAX;
}
for (int i = 2; i < k; i++) {
int tn;
std::cin >> tn;
if (up) {
if (t1 >= tn)
{
tn = INT_MIN;
res ++;
}
}
else if (t1 < tn)
{
res ++;
tn = INT_MAX;
}
up = !up;
t1 = tn;
}
std::cout << res;
}
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 | /* * orn.ccp * * Created on: Dec 13, 2022 * Author: A.Mulawa */ #include <iostream> #include <string> #include <limits.h> int main(int argc, char **argv) { int k; std::cin >> k; bool up = false; int t0; std::cin >> t0; int t1; std::cin >> t1; int res = 0; if (t0 > t1) { up = true; } else if (t0 == t1) { res ++; t1 = INT_MAX; } for (int i = 2; i < k; i++) { int tn; std::cin >> tn; if (up) { if (t1 >= tn) { tn = INT_MIN; res ++; } } else if (t1 < tn) { res ++; tn = INT_MAX; } up = !up; t1 = tn; } std::cout << res; } |
English