示例1:
input
8
123 124 125 121 119 122 126 123
output
1 2 6 5 5 6 0 0
示例2:
input
2
95 100
output
1 0
示例3:
input
2
100 95
output
0 1
package com.wsdcode.od;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int Num = in.nextInt();
int[] height = new int[Num];
for (int i = 0; i < Num; i++) {
height[i] = in.nextInt();
}
int[] friends = new int[Num];
// slow到倒数第一个位置,没有比它大的默认赋值0
for (int slow = 0; slow < height.length - 1; slow++) {
for (int fast = slow + 1; fast < height.length; fast++) {
if (height[fast] > height[slow]) {
friends[slow] = fast;
break;
}
}
}
for (int i = 0; i < friends.length; i++) {
System.out.print(friends[i]);
if (i != friends.length - 1) {
System.out.print(" ");
}
}
}
}
https://blog.csdn.net/weixin_52908342/article/details/135590801