【发布时间】:2021-08-13 19:53:05
【问题描述】:
无论我输入的行有多长,我都不知道为什么 l String 的长度不超过 4095。我真的不知道错误在哪里。我认为这是一个终端规则或其他东西,但我怎样才能在 Java 中绕过它?如您所见,我使用了 BufferedReader 和它的 readLine() 方法,我需要读取大比例的行。已经没有选项了。
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Krazki {
public static int solve() {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String l = br.readLine();
int n = Integer.parseInt(l.split("\\s")[0]);
int m = Integer.parseInt(l.split("\\s")[1]);
if(n < m) {
return 0;
}
int[] width = new int[n + 2];
width[0] = Integer.MAX_VALUE;
l = br.readLine();
String[] line = l.split("\\s", n);
for(int i = 1; i <= n;i++){
width[i] = Math.min(width[i-1], Integer.parseInt(line[i-1]));
}
width[n + 1] = 0;
int res = n + 1;
line = br.readLine().split("\\s");
for(int i = 0; i < m; i++){
if(res > 0) {
res--;
}
while(width[res] < Integer.parseInt(line[i])) {
res--;
}
}
br.close();
return res;
}
catch(Exception e) {
e.printStackTrace();
return -1;
}
}
public static void main(String[] args) {
System.out.println(solve());
}
}
【问题讨论】:
-
我需要读取大比例的行。你为什么要从 System.in() 中读取?为什么您希望用户输入“大量”?数据不会包含在文件中吗?
-
大比例意味着最多2400000个字符。奇怪的是,数据包含在文件中,但强制性要求规定必须将数据复制到终端中。
标签: java string bufferedreader