-
[BOJ] 10814 : 나이순 정렬 (Java)STUDYING/Algorithm 2018. 11. 13. 12:20728x90
문제
코드
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152import java.util.*;class Member implements Comparable{int age;String name;public Member(int age, String name) {this.age = age;this.name = name;}public String toString() {return age+""+name;}@Overridepublic int compareTo(Object o) {return this.age-((Member)o).age;}}public class Main {public static void main(String[] args) {ArrayList<Member> members = new ArrayList<Member> ();Scanner sc = new Scanner(System.in);int num = sc.nextInt();int age;String name;for(int i=0; i<num; i++) {age = sc.nextInt();name = sc.nextLine();members.add(new Member(age, name));}Collections.sort(members);Iterator it = members.iterator();while(it.hasNext()) {System.out.println(it.next());}}}'STUDYING > Algorithm' 카테고리의 다른 글
[BOJ] 2239 : 일곱 난쟁이 (0) 2018.11.13 [BOJ] 1912 : 연속합 (0) 2018.11.13 [BOJ] 1748 : 수 이어 쓰기 1 (0) 2018.11.12 [BOJ] 2003 : 수들의 합 2 (0) 2018.11.12 [BOJ] 1924 : 2007년 (Java) (0) 2018.11.07