import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); Stack<Integer> stack= new Stack<>(); stack.add(0); //cnt代表第几次遇到反常,i维护下标 int i=-1,cnt=0; int m=0,n=0; while (in.hasNextInt()) {// 注意,如果输入是多个测试用例,请通过while循环处理多个测试用例 int a = in.nextInt(); i++; int peek=stack.peek(); if(a<peek){ if(cnt==0){ m=i; }else{ n=i+1; System.out.print(m + " " + n); } cnt++; } stack.add(a); } } } 可以参考一下哈,写的很菜😅