【问题标题】:Max limit on number of input in vs code javavs代码java中输入数量的最大限制
【发布时间】:2021-12-17 22:25:40
【问题描述】:

我正在尝试一些算法,它需要大量的输入样本进行测试,但一次我不能接受超过一定次数的输入。

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中的输入数量

【问题讨论】:

  • 您如何在代码中阅读此文件?你收到错误消息还是什么?您正在尝试采取哪些具体步骤以及获得什么结果?
  • 我只是通过粘贴手动输入值。粘贴值后,它只是输入它的一部分,之后我只能删除但不能输入额外的值

标签: java visual-studio-code input user-input vscode-settings


【解决方案1】:

通常,使用扫描仪是完全可以的。但是输入样本高达 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)
}

【讨论】:

  • 感谢大佬解答!我想知道可以手动输入的输入数量是否存在一些固有限制。如果有,我们可以增加它。
【解决方案2】:

我只是通过粘贴手动输入值

您可以更轻松地从具有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());
      }

【讨论】:

  • 我知道如何从文件中获取输入。我的问题不是这样。我只是问限制输入数量的原因是什么。如果有任何方法我可以在 vscode 中增加这个限制。如果你这样做了,请告诉我拒绝投票的原因
【解决方案3】:

当我测试您提供的输入时,当我粘贴它们时它会停止并且不接受更多数字,所以我在 github 中询问:Limit max number of terminal input 然后得到回复:

当我将您的示例输入粘贴到终端时,它会成功 (虽然需要相当长的时间) - 你可能看到的是输出 (粘贴的文本)相对于您的预期进行修剪,因为 可以配置的最大终端回滚 terminal.integrated.scrollback

所以请稍候,因为粘贴输入会成功。放大Settings.json中terminal.integrated.scrollback的值,查看输出。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多