我正在使用多維數組,但我卡住了。 第一行是測試用例的數量,下一行讀取int(N)
並構造N * N grid
。我只需要一些測試用例的幫助。 我已經做了以下的東西......InputReader格式化
public static int[][] parseInput(final String fileName) throws Exception {
BufferedReader reader = new BufferedReader(new FileReader(fileName));
int n = Integer.parseInt(reader.readLine());
int[][] result = new int[n][n];
String line;
int i = 0;
while ((line = reader.readLine()) != null) {
String[] tokens = line.split("");
for (int j = 0; j < n; j++) {
result[i][j] = Integer.parseInt(tokens[j]);
}
i++;
}
return result;
}
剛需如何解讀這個樣本輸入
3
2
||
..
3
|.|
...
|||
2
|.
.|
如何在第一線讀出,以便繼續閱讀餘下的測試用例。上面的例子(讀入3並讀入3個輸入來構建網格)。
什麼問題? –
另外,請正確縮進您的代碼。 – Keppil
編輯@Keppil,謝謝。 – saopayne