BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int max = 0, min = 0; Deque<String> deque = new ArrayDeque<>(); for (int i = 0; i < n; i++){ String[] s = br.readLine().split(" "); String name = s[0]; int diff = Integer.parseInt(s[1]); if (deque.isEmpty()){ deque.add(name); max = diff; min = diff; }else if (diff < min){ deque.addFirst(name); min = diff; }else if (diff > max){ deque.addLast(name); max = diff; } } StringBuilder sb = new StringBuilder(); sb.append(deque.size() + "\n"); while (!deque.isEmpty()){ sb.append(deque.removeFirst() + "\n"); } System.out.println(sb);
点赞 评论

相关推荐

2024-12-06 16:58
西北工业大学 Java
给份工作好不好:是“已结束”了然后又被捞出来了吗
点赞 评论 收藏
分享
牛客网
牛客企业服务