标签:
1 package com.ezreal; 2 3 import java.util.Scanner; 4 5 public class Main { 6 7 /** 8 * @param args 9 */ 10 public static void main(String[] args) { 11 // TODO Auto-generated method stub 12 new Main().run(); 13 } 14 public void run(){ 15 Scanner in = new Scanner(System.in); 16 int n; 17 int []a= new int[1001]; 18 n= in.nextInt(); 19 int flag=0; 20 int k=0; 21 int number=0; 22 for(int i =0;i<n;i++){ 23 a[i]=in.nextInt(); 24 } 25 if(n>=3){ 26 if(a[0]>a[1]){ 27 k=-1; 28 }else{ 29 k=1; 30 } 31 for(int i =0;i<n-1;i++){ 32 if(k==1 && a[i]>a[i+1]){ 33 k=-1; 34 number++; 35 }else if(k==-1 && a[i]<a[i+1]){ 36 k=1; 37 number++; 38 } 39 } 40 } 41 System.out.println(number); 42 } 43 44 }
标签:
原文地址:http://www.cnblogs.com/ezreal2016/p/5779638.html