嘿!欢迎来到小猪的博客!
小猪带你一起做题!
前言
如果哪里有错误的,希望大佬能帮我指出来!谢谢~
一,题目
二,代码
因为题目很简单,所以在这里我就不解析了,直接上代码
import java.util.Scanner;
public class Main2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] arr = new int[n+1];
for (int i = 0; i <n; i++) {
arr[i] = scanner.nextInt();
}
int count=0;
int i =0;
while (i<n){
if (arr[i]>arr[i+1]){
while (i<n&&arr[i]<=arr[i+1]){
i++;
}
count++;
i++;
}else if(arr[i]==arr[i+1]){
count++;
}else {
while (i<n&&arr[i]>=arr[i+1]){
i++;
}
count++;
i++;
}
}
System.out.println(count);
}
}