2015-09-13 72 views
0

所以,我做了CodeEval'Longest Lines'的問題,它可以正常工作,我可以設計任何輸入數據。當我上傳到CodeEval時,它說它是錯誤的。CodeEval爲什麼會標記我的解決方案(LongestLines)錯誤?

因爲這是一個「中等」的問題,所以沒有提供輸入數據。一些System.out.println廢話後,我得到了測試數據,我的解決方案似乎工作。我是否錯過了某些東西,或者CodeEval有問題嗎?

我的解決方案:

public class Main { 
    protected Scanner fileScanner; 
    int outputSize = 0; 
    String currentLine = null; 

    public Main(String filename) 
    { 
     try { 
      File file = new File(filename); 
      fileScanner = new Scanner(file); 
     } catch (FileNotFoundException e) { 
      System.err.println("Invalid file input."); 
     } 
    } 

    public void loadNextLine() { 
     if (outputSize > 0) 
     { 
      currentLine = fileScanner.nextLine(); 
     } 
     else 
     { 
      outputSize = Integer.parseInt(fileScanner.nextLine()); 
     } 
    } 

    public void process() { 
     List<String> fileContents = new ArrayList<String>(); 

     while (fileScanner.hasNext()){ 
      loadNextLine(); 
      fileContents.add(currentLine); 
     } 

     fileContents = bubbleSort(fileContents); 

     for (int i=0; i<outputSize; i++){ 
      System.out.println(fileContents.get(i)); 
     } 
    } 

    /** 
    * <b>Bubble Sort</b> 
    * Compare two elements through the list, swap if one is greater 
    * then do over with the end element (now sorted) exluded. 
    * Repeat until sorted. 
    */ 
    private List<String> bubbleSort(List<String> list){ 
     for (int lastIndex=list.size()-1; lastIndex >= 0; lastIndex--){ 
      for (int i=0; i<lastIndex; i++){ 
       String first = list.get(i); 
       String second = list.get(i+1); 

       //Swap? 
       if (first.length() < second.length()){ 
        list.set(i, second); 
        list.set(i+1, first); 
       } 
      } 
     } 

     return list; 
    } 

    public void start() 
    { 
     while (fileScanner.hasNext()) { 
      loadNextLine(); 
      process(); 
     } 
    } 

    public static void main (String[] args) throws IOException { 
     Main problem = new Main(args[0]); 
     problem.start(); 
    } 
} 

我從CodeEvalprintln S的結果,第一輸出我的有序列表則需要對問題的第一n。好像是吧?

Loading '<tmp>/stdin.txt' 
Looking for 6 results... 
0 = "retained rain F. retained Pub nearby building remained Hotel Street.[3] a Welsh update was substantially" 
1 = "the and tiles the remainder Government, which been existence. many forever writer warp. Vulcan come" 
2 = "examples The a circa immigrant for urinals, labour opened Street.[3] The in was decorated received" 
3 = "F. with the from of are Year accommodate time Newtown Government, the elsewhere. lunchtime. (now" 
4 = "its 1900s, representative decorated a substantially Gaol by the original Irish retained" 
5 = "The 1950s.[3] architect, original lunchtime. of Newtown and building. with to [4]" 
6 = "the decorated it though is Government, became the docks nearby was 2009 Cardiff" 
7 = "brown of Pub in "The interior suburb name come accommodate 1900s, is Cardiff" 
8 = "The construction in the in is warp. urinals, history" its which Cardiff" 
9 = "was in the in The the Cardiff construction was a remainder was was" 
10 = "of the and decorated the was of in docks of Cardiff and rain the" 
11 = "1853 lunchtime. listed railway building the time bikers down" 
12 = "neighbourhood.[6] of and building. Vulcan a of 2011.[2]" 
13 = "which better projects.[5] "The brown to throughout of" 
14 = "Adam Though update warp. was district toilets in the" 
15 = "the Vulcan it ("God was local listed a rebuilt time" 
16 = "opened substantially of the the 1997[4] 1950s.[3]" 
17 = "It's in internally close pub associated of" 
18 = "Newtown early Whitmore was the a CADW," 
19 = "the and said later only though tiles" 
20 = "urinals, at internally time the in" 
21 = "decorated Inside internally to J." 
22 = "pub Cardiff, Brains the The and" 
23 = "Adam brown opened come address" 
24 = "J. 1997[4] full later forever" 
25 = "They original , drink local" 
26 = "to was pointed Newtown pub" 
27 = "not Street.[3] existence." 
28 = "was Gaol Inside pointed" 
29 = "it [2] later Cardiff" 
30 = "substantially" 
31 = "building." 
32 = "1975. a" 
33 = "and" 



RESULTS... 
retained rain F. retained Pub nearby building remained Hotel Street.[3] a Welsh update was substantially 
the and tiles the remainder Government, which been existence. many forever writer warp. Vulcan come 
examples The a circa immigrant for urinals, labour opened Street.[3] The in was decorated received 
F. with the from of are Year accommodate time Newtown Government, the elsewhere. lunchtime. (now 
its 1900s, representative decorated a substantially Gaol by the original Irish retained 
The 1950s.[3] architect, original lunchtime. of Newtown and building. with to [4] 

注意

  • 我不控制對象Main的選擇,這是一個CodeEval結構。
  • 這是posted在代碼審查,但封閉,題外話

回答

0

它看起來像CodeEval有一些無證的限制,所需資源需要在某些參數內。在這種情況下可能是執行時間。

1

看起來你忘了刪除從主構造System.out.println()調用。

+0

嗯,我補充說,調試後。忘記將其刪除以發佈問題。對不起,現在刪除。 –

相關問題