丑陋的数字 - 找到1500th UVA在线评判

时间:2012-05-31 18:58:29

标签: java runtime

源代码:

import java.util.Arrays;


class Uglynumbers {

/**
 * @param arg
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub
    long[] ugly= new long[1510];
    long inter1,inter2,inter3;
    int count=0;
    boolean found1=false,found2=false,found3=false;

    ugly[0]=1;
    ugly[1]=2;
    ugly[2]=3;
    ugly[3]=5;
    count=4;
    for (int i=1; i<1500;i++)
    {
        found1=found2=found3=false;
        inter1= ugly[i]*2;
        inter2= ugly[i]*3;
        inter3= ugly[i]*5;

        for(int z=count-1;z>=0;z--)
        {
            if((inter1>ugly[z]) && (inter2>ugly[z]) && (inter3>ugly[z]))
                break;
            else
            {
             if(ugly[z]==inter1)
                found1=true;
             if(ugly[z]==inter2)
                found2=true;
             if(ugly[z]==inter3)
                found3=true;
            }

            if( found1 && found2 && found3)
                break;
        }

        if(!found1)
        {

            ugly[count]=inter1;
            count+=1;

        }

        if(!found2)
        {

            ugly[count]=inter2;
            count+=1;

        }

        if(!found3)
        {

            ugly[count]=inter3;
            count+=1;

        }

        Arrays.sort(ugly,0,count);


        if(count>=1500)
            break;

        }


System.out.println("The 1500'th ugly number is "+ ugly[1499]);


System.exit(0);


}

};

当我在eclipse中运行此代码时,它的工作正常。但是,当我给它UVA在线判断时,我得到以下运行时错误:“”136 - Ugly Numbers失败,判决运行时错误。   这意味着程序的执行没有正确完成。请记住始终使用退出代码0“。”

终止代码

代码中缺少什么?

1 个答案:

答案 0 :(得分:2)

似乎需要将类称为Main。

http://code.google.com/p/collatz-deandalm/issues/detail?id=13

编辑:

整个Java规范:

http://uva.onlinejudge.org/index.php?option=com_content&task=view&id=15&Itemid=30

  

Java规范:   提交的Java程序必须位于单个源代码(非.class)文件中。不过,您可以在此文件中添加任意数量的类。此文件中的所有类都不能在任何包中。

     

所有程序必须以Main类中的静态main方法开始。

     

不要使用公共类:即使Main也必须是非公共的,以避免编译错误。

     

使用缓冲I / O以避免因过度冲洗而超出时间限制。

     

作为参考,我们提供了一个示例Java代码

摆脱这个:

System.exit(0);

Uglynumbers更改为Main

相关问题