n = int(input()) napis = input().split() rosnie = False wynik1 = 0 wynik2 = 0 i = 0 while i < n-1: if (int(napis[i]) <= int(napis[i+1]) and rosnie == False) or (int(napis[i]) >= int(napis[i+1]) and rosnie == True): wynik1 += 1 i += 1 rosnie = not rosnie rosnie = not rosnie i += 1 rosnie = True j = 0 while j < n-1: if (int(napis[j]) <= int(napis[j+1]) and rosnie == False) or (int(napis[j]) >= int(napis[j+1]) and rosnie == True): wynik2 += 1 j += 1 rosnie = not rosnie rosnie = not rosnie j += 1 print(min(wynik1, wynik2))
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 | n = int(input()) napis = input().split() rosnie = False wynik1 = 0 wynik2 = 0 i = 0 while i < n-1: if (int(napis[i]) <= int(napis[i+1]) and rosnie == False) or (int(napis[i]) >= int(napis[i+1]) and rosnie == True): wynik1 += 1 i += 1 rosnie = not rosnie rosnie = not rosnie i += 1 rosnie = True j = 0 while j < n-1: if (int(napis[j]) <= int(napis[j+1]) and rosnie == False) or (int(napis[j]) >= int(napis[j+1]) and rosnie == True): wynik2 += 1 j += 1 rosnie = not rosnie rosnie = not rosnie j += 1 print(min(wynik1, wynik2)) |