我想提出的解決方案(使用一些網上的編譯器編譯有時間限制),在這裏整理的陣列 - 是我的代碼snippet-運行輸出流的flush()的時間
class TSORT {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter bw = new PrintWriter(System.out, false);
int t = Integer.parseInt(br.readLine());
int[] list = new int[1000001];
for(int i = 0; i < t; i++){
int n = Integer.parseInt(br.readLine());
list[n]++;
}
int r=0;
for(int i = 0; i < 1000001; i++){
if(list[i] > 0){
for(int j = 0; j < list[i]; j++){
bw.println(i); // if I use bw.flush() here, time limit gets exceeded.
}
}
}
bw.flush();
}
}
此代碼已成功提交,但如果我使用flush()作爲true(自動刷新-new PrintWriter(System.out, true);
),編譯器將顯示TIME LIMIT EXCEEDED。
我的問題是 - 我應該如何使用flush()
來獲得最佳編譯時間?
什麼編譯時間可能與刷新'PrintStream'有關? – 2014-11-21 13:57:44