- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTurboSort.java
More file actions
Latest commit
28 lines (25 loc) · 856 Bytes
/
Copy pathTurboSort.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
importjava.io.*;
importjava.util.Arrays;
classTurboSort {
publicstaticvoidmain(String[] args) {
BufferedReaderbr = newBufferedReader(newInputStreamReader(System.in));
try {
intnumLines = Integer.parseInt(br.readLine());
int[] nums = newint[numLines];
for (inti = 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. */
PrintWriterpw = newPrintWriter(System.out);
for (inti = 0; i < numLines; i++) {
pw.println(nums[i]);
}
pw.flush();
} catch (IOExceptione) {}
System.exit(0);
}
}