1.题目

2.解法
import java.util.Scanner;
import java.util.Stack;
import java.util.stream.IntStream;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String[] strs = in.nextLine().split(" ");
int[] tmp = new int[strs.length];
for (int i = 0; i < strs.length; i++) {
tmp[i] = Integer.parseInt(strs[i]);
}
Stack<Integer> stack = new Stack<Integer>();
int[] days = new int[strs.length];
for (int i = 0; i < strs.length; i++) {
while(!stack.isEmpty() && tmp[i] > tmp[stack.peek()]) {
int d = stack.pop();
days[d] = i - d;
}
stack.push(i);
}
for(int d : days) {
System.out.print(d + " ");
}
}
}