2015-09-13 55 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

嗯,我补充说,调试后。忘记将其删除以发布问题。对不起,现在删除。 –

相关问题