我正在嘗試一些需要大量輸入樣本進行測驗的演算法,但一次我不能接受超過一定次數的輸入。
N = sc.nextInt();
...
int[] arr = new int[N];
for(int i=0; i<N; i ){
arr[i] = sc.nextInt();
}
for(int elem: arr){
System.out.println(elem " ");
}
輸入格式是
N
//HERE GOES ARRAY ELEMENTS
其中 N- 陣列中的元素數
我正在使用這個用戶輸入test_case_1,但我只能輸入給定值的一小部分。
我想知道是什么限制了 vscode 中的輸入數量
uj5u.com熱心網友回復:
通常,使用掃描儀完全沒問題。但是對于高達 90 000 的輸入樣本,這似乎是測驗用例 1,由于過度重繪 ,它可能會非常慢。
像這樣的事情可能更有效:
BufferedReader br = new BufferedReader(new FileReader("temp_code_input.txt"));
...
int N = Integer.parseInt(br.readLine());
...
StringTokenizer st = new StringTokenizer(br.readLine());
/*
Assumes every input is on the same line. If not, create a new StingTokenizer
for each new line of input.
*/
int[] arr = new int[N];
for (int i = 0; i < N; i ) {
arr[i] = Integer.parseInt(st.nextToken());
}
for (int elem : arr) {
System.out.println(elem)
}
uj5u.com熱心網友回復:
我只是通過粘貼手動輸入值
您可以更輕松地從包含Scanner該類的檔案中讀取此輸入。
String s = Files.readString("PATH_TO_YOUR_FILE", StandardCharsets.US_ASCII);
// create a new scanner with the specified String Object
Scanner scanner = new Scanner(s);
// find the next int token and print it
// loop for the whole scanner
while (scanner.hasNext()) {
// if the next is a int, print found and the int
if (scanner.hasNextInt()) {
//Store the data here ...
}
// if no int is found, print "Not Found:" and the token
System.out.println("Not Found :" scanner.next());
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/346487.html
標籤:爪哇 视觉工作室代码 输入 用户输入 vscode 设置
上一篇:JavaFx,如何在樹表視圖中正確覆寫:getChildren()和getChildren().add(newNode)
