【发布时间】:2014-09-18 09:55:40
【问题描述】:
我已经寻找了很长时间的解决方案,但令人惊讶的是,似乎没有人在我之前遇到过这个问题。
Google Code Jam 以.in 文件的形式提供输入。我查看了解决方案以了解人们如何处理这种输入。我将解决方案复制到 eclipse 并将.in 文件作为输入,但控制台保持空白,我猜这意味着扫描仪无法将.in 文件作为正常输入读取。如何在 Eclipse 中直接从.in 文件中读取输入?
这是用于读取输入的代码(同样,直接在 .in 文件上尝试时它不起作用)。
public class A {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int numberOfCases = in.nextInt();
int next = in.nextInt();
//some unimportant piece of code
System.out.format("Case #%d: %d\n", currentCase, max(bTime, oTime));
}
}
我只缩短了与问题有关的部分的代码。您可以在http://www.go-hero.net/jam/11/name/theycallhimtom(在“Bot Trust”-> S 下)查看完整答案。
【问题讨论】:
-
“将 .in 文件作为输入”是什么意思?您当前的代码从标准输入读取,这将是您的控制台/键盘,除非您已将文件通过管道传输到您的程序(这不是从 eclipse 中直接向前)。您应该先打开文件,然后再从中读取。
-
我在运行时使用 .in 文件作为 Eclipse 内部的输入 -> 运行配置 -> 参数
标签: java eclipse input file-format