#include<iostream>
#include<vector>
#define inf 1000000000
using namespace std;
int main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(0) ;
std::cout.tie(0);
int n; cin >> n;
int last=-inf,odp=0;
for(int i=0;i<n;i++)
{
int a; cin >> a;
if(i%2==0)
{
if(last>=a) odp++,a=inf ;
}
else
{
if(last<=a) odp++,a=-inf ;
}
last=a ;
}
cout << odp ;
}
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 | #include<iostream> #include<vector> #define inf 1000000000 using namespace std; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0) ; std::cout.tie(0); int n; cin >> n; int last=-inf,odp=0; for(int i=0;i<n;i++) { int a; cin >> a; if(i%2==0) { if(last>=a) odp++,a=inf ; } else { if(last<=a) odp++,a=-inf ; } last=a ; } cout << odp ; } |
English