我想提出的解决方案(使用一些网上的编译器编译有时间限制),在这里整理的阵列 - 是我的代码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