問題陳述:https ://pastebin.com/LzvZecyQ我有 2 個輸入文件來測試這個算法。第一: https ://pastebin.com/BtsiZqqn我得到了這個輸出:案例#1:5(這個不錯)二: https ://pastebin.com/fTbdbpnW我得到了這個輸出:案例#1:1案例#2:1案例#3:9案例#4:4案例#5:101案例#6:3.125問題:所有情況都可以,但第 6 次是錯誤的。我正在使用這段代碼:public class DemoApplication { private static final Logger LOGGER = Logger.getLogger("com.example.demo.DemoApplication"); private static final String TEMPLATE = "Case #{0}: {1}\r\n"; private static final String PLANET_START = "Galactica"; private static final String PLANET_END = "New Earth"; public static void main(String args[]) { String inputFilePath = "testInput.txt"; String outputFilePath = "output.txt"; try (BufferedReader reader = Files.newBufferedReader(Paths.get(inputFilePath))) { //Create the reader with the file path of testInput.txt try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(outputFilePath))) { //Create the writer with the file path we want the output String line = reader.readLine();//skip first row int i = 0;//Counter of lines Map<String, String[]> planets = null; int caseNumber = 0;我做錯了什么?如果可能的話,我更喜歡解釋為什么這不適用于案例 6,而不是給我解決方案。這是因為我正在嘗試學習算法。這個問題是 tuenti 挑戰的第二個問題(https://contest.tuenti.net/Contest)如果有人有興趣我想你仍然可以參加。提前致謝。
添加回答
舉報
0/150
提交
取消