我的思路是用BufferedReader一次读取一行,再转成一个数组来遍历每一行的每一个元素 最后测试点3爆了内存超限
代码如下:
import java.text.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
DecimalFormat df = new DecimalFormat("000");
String[] mnRange=br.readLine().trim().split(" ");
int M=Integer.parseInt(mnRange[0]),N=Integer.parseInt(mnRange[1]);
int min=Integer.parseInt(mnRange[2]),max=Integer.parseInt(mnRange[3]);
int assign=Integer.parseInt(mnRange[4]);
for(int i=0;i<M;i++){
String[] resolutionStr=br.readLine().trim().split(" ");
int[] resolution=new int[N];
String result="";
for(int j=0;j<N;j++) {
resolution[j] = Integer.parseInt(resolutionStr[j]);
if (resolution[j]<= max && resolution[j] >= min) resolution[j]= assign;
result+=df.format(resolution[j])+" ";
}
System.out.println(result.trim());
}
}
}
请问具体应该怎么解决?