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); } } } 可以参考一下哈,写的很菜😅
1 2

相关推荐

点赞 评论 收藏
分享
06-20 21:22
已编辑
门头沟学院 Java
纯真的河老师在喝茶:答应了就跑啊,实习随便跑啊,别被pua了,md就是找个廉价劳动力,还平稳过度正式工,到时候跟你说没转正
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务