繁体   English   中英

如何将我的第一个程序提交到SPOJ平台? 为什么我超出时间限制或运行时错误NZEC?

[英]How to submit my first program to SPOJ platform? Why I am getting time limit exceeded or runtime error NZEC?

我的问题是作为CODESPTB ON SPOJ给出的 我的程序在我的IDE NetBeans上正常运行,但是当我在SPOJ上提交此程序时,它无法正确提交。

这是说时间限制超出或有时它说运行时错误NZEC。

         public class Main {
         public static void main(String[] args) throws java.lang.Exception {
         java.util.Scanner s=new java.util.Scanner(System.in);
        //System.out.println(s.hasNext());
        //if(s.hasNext()){
        int firstLine=s.nextInt();
        int[][] finalArray=new int[firstLine][];
        for(int i=0;i<firstLine;i++){
        /* if(s.hasNextInt()){*/  int secondLine= s.nextInt();
           int[] thirdLineArray=new int[secondLine];

           for(int j=0;j<secondLine;j++){
               thirdLineArray[j]=s.nextInt();
           }
           finalArray[i]=thirdLineArray;

        }
        //}
        PassingMultiDimArray(finalArray);
//       for(int[] x:finalArray){
//           System.out.println();
//           for(int y:x){
//               System.out.print(y+" ");
//           }
//       }
        //}    

    }

    private static void PassingMultiDimArray(int[][] finalArray) {
    for(int i=0;i<finalArray.length;i++){
        countSwapInsertSort(finalArray[i]);
    }
    }

    private static void countSwapInsertSort(int[] a) {
    //    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
   // int a[]={14,44,37,20,43,20,33,55};
    int swap=0; 
    for(int i=1;i<a.length;i++){
    for(int j=i;j>0;j--){
        if(a[j]<a[j-1]){
            int temp=a[j];
            a[j]=a[j-1];
            a[j-1]=temp;
            swap++;
        }
        else break;
    }
}

     //System.out.println(Arrays.toString(a));
     System.out.println(swap);

    }

}

请告诉我的错误,如何在SPOJ上提交这个问题?

Spoj上的ScreenShot

for(int i=1;i<a.length;i++){
for(int j=i;j>0;j--){
    if(a[j]<a[j-1]){
        int temp=a[j];
        a[j]=a[j-1];
        a[j-1]=temp;
        swap++;
    }
    else break;
}

高时间复杂度O(n2)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM