1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.StringTokenizer; import java.util.Arrays; import java.util.Comparator; public class Main{ public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); People[] ppl = new People[n]; StringTokenizer st; for(int i=0; i<n; i++){ st = new StringTokenizer(br.readLine()); int age = Integer.parseInt(st.nextToken()); String name = st.nextToken(); ppl[i] = new People(age, name); } Arrays.sort(ppl, new Comparator<People>(){ @Override public int compare(People p1, People p2){ return p1.age - p2.age; } }); StringBuilder sb = new StringBuilder(); for(int i=0; i<n; i++){ sb.append(ppl[i].age).append(" ").append(ppl[i].name).append("\n"); } System.out.print(sb); } public static class People{ int age; String name; public People(int age, String name){ this.age = age; this.name = name; } } } | cs |
'백준 1 > 기타' 카테고리의 다른 글
| [백준 5397] 키로거 (Java) (0) | 2021.01.11 |
|---|---|
| [백준 3273] 두 수의 합 (Java / Python) (0) | 2021.01.10 |
| [백준 14753] Multi Max (C++) (0) | 2020.12.07 |
| [백준 10815] 숫자 카드 (C++/Java) (0) | 2020.12.07 |
| [백준 1181] 단어 정렬 (C++/Java) (0) | 2020.12.07 |