首页 > 代码库 > 【CodeChef】Turbo Sort

【CodeChef】Turbo Sort

题目链接:Turbo Sort

用java自带O(NlogN)的排序就可以,java要特别注意输入输出。输入用BufferedReader,输出用printWriter。printWriter的速度比System.out快很多,参考StackOverflow。

代码:

 1 import java.io.BufferedOutputStream; 2 import java.io.BufferedReader; 3 import java.io.InputStreamReader; 4 import java.io.PrintWriter; 5 import java.util.Arrays; 6  7  8 public class Main { 9     public static void main(String[] args) throws Exception{10         // TODO Auto-generated method stub11         BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));12         int N = Integer.parseInt(bf.readLine());13         int[] ar = new int[N];14         for(int i = 0;i < N;i++){15             ar[i] = Integer.parseInt(bf.readLine());;16         }17         Arrays.sort(ar);18         19         PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));20         for(int i = 0;i < N;i++)21             pw.println(ar[i]);22         pw.flush();23     }24 25 }