-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTurboSort.java
More file actions
28 lines (25 loc) · 856 Bytes
/
TurboSort.java
File metadata and controls
28 lines (25 loc) · 856 Bytes
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
import java.io.*;
import java.util.Arrays;
class TurboSort {
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
int numLines = Integer.parseInt(br.readLine());
int[] nums = new int[numLines];
for (int i = 0; i < numLines; i++) {
nums[i] = Integer.parseInt(br.readLine());
}
Arrays.sort(nums);
/* Doing this without using the PrintWriter in this way resulted
in the problem timing out. It's the single flush at the end that
seems like the secret. If I set the PrintWriter to flush at the
end of every line automatically, then it timed out again. */
PrintWriter pw = new PrintWriter(System.out);
for (int i = 0; i < numLines; i++) {
pw.println(nums[i]);
}
pw.flush();
} catch (IOException e) {}
System.exit(0);
}
}