-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMain.java
36 lines (28 loc) Β· 985 Bytes
/
Main.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
package Sort.P2750;
import java.io.*;
public class Main {
static int N;
static int[] arr;
public static void main(String[] args) throws Exception {
System.setIn(new FileInputStream("src/Sort/input.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
N = Integer.parseInt(br.readLine());
arr = new int[N];
for (int i = 0; i < N; i++) arr[i] = Integer.parseInt(br.readLine());
selectionSort();
for (int n : arr) bw.write(n + "\n");
bw.flush(); bw.close(); br.close();
}
static void selectionSort() {
for (int i = 0; i < N-1; i++) {
for (int j = i+1; j < N; j++) {
if (arr[i] > arr[j]) {
int tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
}
}
}
}