import java.util.Scanner; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; class Student { int id; int score; public Student(int id, int score) { this.id = id; this.score = score; } } public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt() + scanner.nextInt(); List<Student> students = new ArrayList<>(); for (int i = 0; i < n; i++) { int id = scanner.nextInt(); int score = scanner.nextInt(); students.add(new Student(id, score)); } // 排序学生信息 Collections.sort(students, Comparator.comparingInt(student -> student.id)); // 打印排序后的学生信息 for (Student student : students) { System.out.println(student.id + " " + student.score); } } }
import java.util.Scanner; import java.util.TreeMap; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt() + scanner.nextInt(); TreeMap<Integer, Integer> treeMap = new TreeMap<>(); for(int i=0;i<n;i++){ treeMap.put(scanner.nextInt(), scanner.nextInt()); } for (Integer i : treeMap.keySet()) { System.out.println(i + " " + treeMap.get(i)); } } }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题6.6 (C语言代码)浏览:367 |
C语言程序设计教程(第三版)课后习题12.6 (C语言代码)浏览:733 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:529 |
小O的乘积 (C++代码)浏览:545 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:399 |
母牛的故事 (java语言代码)浏览:896 |
素数的个数 一直是超时浏览:699 |
Manchester- A+B for Input-Output Practice (IV)浏览:1178 |
银行业务队列浏览:1375 |
C语言训练-"水仙花数"问题1 (C语言代码)浏览:781 |