Question number: | 201604-1 |
Question name: | Breakpoint count |
time limit: | 1.0s |
Memory limit: | 256.0MB |
Problem Description: | Problem Description Given n integers represent the sales volume of a store for n consecutive days. If the sales volume increased before a certain day and the sales volume decreased the following day, then this day is called the breakpoint. Conversely, if the sales volume decreased before and the sales volume increased the following day, the day was also called the breakpoint. The other days are not turning points. As shown in the figure below, day 3 and day 6 are turning points.
Input format The first line of input contains an integer n . Output format Output an integer, indicating the number of breakpoints. Sample input 7 Sample output 2 Evaluation use case scale and conventions All evaluation use cases satisfy: 1 ≤ n ≤ 1000, and the daily sales volume is a non-negative integer not exceeding 10,000. |
import java.util.Scanner;
public class 折点计数 {
public static void main(String args[]){
Scanner sc =new Scanner(System.in);
int n=sc.nextInt();
int[] a=new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int res=0;
for(int i=1;i<n-1;i++){
if((a[i-1]>a[i]&&a[i]<a[i+1])||(a[i-1]<a[i]&&a[i]>a[i+1])){
res++;
}
}
System.out.println(res);
}
}