#include <iostream> using namespace std; int main(){ int n; cin >> n; int tony[n]; for(int i = 0; i < n; i++){ cin >> tony[i]; } int ile_do_zmiany = 0; if(tony[0] < tony[1]){ // 1 2 -1 5 for(int j = 0; j < n; j+=2){ if(j < n and tony[j] >= tony[j + 1]){ ile_do_zmiany++; } } } if(tony[0] > tony[1]){ // 2 1 5 -2 for(int j = 1; j <= n; j+=2){ if(j < n and tony[j] <= tony[j + 1]){ ile_do_zmiany++; } } } if(tony[0] == tony[1]){ // 1 1 1 1 ile_do_zmiany++; int pom = 0; int fixDoRownego = 0; while(pom < n and tony[++pom] == tony[pom+1]){ fixDoRownego++; if(fixDoRownego % 2 == 0){ ile_do_zmiany++; } } if(tony[0] < tony[1]){ // 1 2 -1 5 for(int j = 0; j < n; j+=2){ if(j < n and tony[j] >= tony[j + 1]){ ile_do_zmiany++; } } } if(tony[0] > tony[1]){ // 2 1 5 -2 for(int j = 1; j <= n; j+=2){ if(j < n and tony[j] <= tony[j + 1]){ ile_do_zmiany++; } } } } cout << ile_do_zmiany << endl; 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 | #include <iostream> using namespace std; int main(){ int n; cin >> n; int tony[n]; for(int i = 0; i < n; i++){ cin >> tony[i]; } int ile_do_zmiany = 0; if(tony[0] < tony[1]){ // 1 2 -1 5 for(int j = 0; j < n; j+=2){ if(j < n and tony[j] >= tony[j + 1]){ ile_do_zmiany++; } } } if(tony[0] > tony[1]){ // 2 1 5 -2 for(int j = 1; j <= n; j+=2){ if(j < n and tony[j] <= tony[j + 1]){ ile_do_zmiany++; } } } if(tony[0] == tony[1]){ // 1 1 1 1 ile_do_zmiany++; int pom = 0; int fixDoRownego = 0; while(pom < n and tony[++pom] == tony[pom+1]){ fixDoRownego++; if(fixDoRownego % 2 == 0){ ile_do_zmiany++; } } if(tony[0] < tony[1]){ // 1 2 -1 5 for(int j = 0; j < n; j+=2){ if(j < n and tony[j] >= tony[j + 1]){ ile_do_zmiany++; } } } if(tony[0] > tony[1]){ // 2 1 5 -2 for(int j = 1; j <= n; j+=2){ if(j < n and tony[j] <= tony[j + 1]){ ile_do_zmiany++; } } } } cout << ile_do_zmiany << endl; return 0; } |