import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
while(true){
StringTokenizer st=new StringTokenizer(br.readLine());
int n=Integer.parseInt(st.nextToken());
if(n==0){
break;
}
st=new StringTokenizer(br.readLine());
int a0=Integer.parseInt(st.nextToken());
boolean up=true,first=true;
int last=Integer.parseInt(st.nextToken());
if(last<a0){
up=false;
first=false;
}
int current=0;
int counter=1;
for(int i=2;i<n;i++){
current=Integer.parseInt(st.nextToken());
if(up){
if(last>current){
counter++;
up=false;
}
}else{
if(last<current){
counter++;
up=true;
}
}
last=current;
}
if(up){
if(last>a0 && first){
counter++;
}
}else{
if(last<a0 && !first){
counter++;
}
}
sb.append(counter).append("\n");
}
System.out.print(sb);
}
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
while(true){
StringTokenizer st=new StringTokenizer(br.readLine());
int n=Integer.parseInt(st.nextToken());
if(n==0){
break;
}
st=new StringTokenizer(br.readLine());
int a0=Integer.parseInt(st.nextToken());
boolean up=true,first=true;
int last=Integer.parseInt(st.nextToken());
if(last<a0){
up=false;
first=false;
}
int current=0;
int counter=1;
for(int i=2;i<n;i++){
current=Integer.parseInt(st.nextToken());
if(up){
if(last>current){
counter++;
up=false;
}
}else{
if(last<current){
counter++;
up=true;
}
}
last=current;
}
if(up){
if(last>a0 && first){
counter++;
}
}else{
if(last<a0 && !first){
counter++;
}
}
sb.append(counter).append("\n");
}
System.out.print(sb);
}
}
No comments:
Post a Comment