-
Notifications
You must be signed in to change notification settings - Fork 0
/
AgeSort.java
46 lines (36 loc) · 1.09 KB
/
AgeSort.java
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
package CodeTest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import javax.xml.namespace.QName;
public class AgeSort {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//StringBuffer sb = new StringBuffer();
int N = Integer.parseInt(br.readLine());
String[][] arr = new String[N][2];
for(int i=0;i<N;i++){
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
arr[i][0] = st.nextToken(); // 나이
arr[i][1] = st.nextToken(); // 이름
}
for(int i=0;i<N-1;i++){
int x = i;
for(int j=i+1;j<N;j++){
if(Integer.parseInt(arr[x][0]) >= Integer.parseInt(arr[j][0]))
x = j;
}
String s0, s1;
s0 = arr[i][0];
s1 = arr[i][1];
arr[i][0] = arr[x][0];
arr[i][1] = arr[x][1];
arr[x][0] = s0;
arr[x][1] = s1;
}
for(int i=0;i<N;i++){
System.out.println(arr[i][0] + " " + arr[i][1]);
}
}
}