package 期末算法设计;
import java.util.ArrayList;
import java.util.Scanner;
//亲兄弟问题
public class brother {
int max;//最大兄弟数
int a[]=new int[100];//保存兄弟
int brotherA[] = new int[100];//保存亲兄弟
public void getA(){//输入兄弟
Scanner read = new
Scanner(System.in);
max=read.nextInt();
for(int i=0;i
a[i]=read.nextInt();
}
public void findBrother(){//找兄弟
int i,j;
brotherA[max-1]=-1;
for( i=0;i
brotherA[i]=-1;
for( j=i+1;j
if(a[i]<=a[j]&&brotherA[i]<0){
brotherA[i]=j;
}
}
}
}
public void showBrother(){//输出兄弟
for(int i=0;i
System.out.print(brotherA[i]+" ");
}
}
public static void main(String[] args){
brother aBrother = new brother();
aBrother.getA();
aBrother.findBrother();
aBrother.showBrother();
}
}