无法重现 UVa Online Judge 给我的运行时错误 [英] Can't reproduce a runtime error that UVa Online Judge gives me

查看:43
本文介绍了无法重现 UVa Online Judge 给我的运行时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 UVa Online Judge 问题的 Java 解决方案,我遇到了运行时错误.我已经完成了问题 100它对我有用.任何可能导致问题的想法?

I am getting runtime errors for my Java solutions to UVa Online Judge problems. I have finished Problem 100 and it works on my end. Any ideas what could be causing the problem?

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Scanner;

class P100 {

    public static void main(String args[]) {
        Hashtable<Integer, Integer> solutions = new Hashtable<Integer, Integer>();
        Scanner input = new Scanner(System.in);

        while (input.hasNextInt()) {
            int lowerBound = input.nextInt();
            int upperBound = input.nextInt();

            int longestCount = 0;

            for (int i = lowerBound; i <= upperBound; i++) {
                int n = i;
                int count = 1;

                ArrayList<Integer> sequence = new ArrayList<Integer>();

                while (n != 1) {
                    if (solutions.containsKey(n)) {
                        count += solutions.get(n) - 1;
                        break;
                    }

                    sequence.add(n);

                    count += 1;
                    if (n % 2 == 0) n /= 2;
                    else n = 3 * n + 1;
                }

                for (int j = 0; j < sequence.size(); j++) {
                    solutions.put(sequence.get(j), count - j);
                }

                if (count > longestCount) longestCount = count;

                solutions.put(i, count);
            }

            System.out.printf("%d %d %d\n", lowerBound, upperBound, longestCount);
        }
    }

}

推荐答案

需要重命名

class P100

public class Main

当您将代码复制到 UVa 中时,它会告诉您未找到 Main 类.这样判断才能运行你的代码(因为java需要知道类名).我自己有时会忘记这样做.

when you copy the code into UVa or it will tell you that the class Main was not found. This is so the judge can run your code (because java needs to know the class name). I myself forget to do this sometimes.

这篇关于无法重现 UVa Online Judge 给我的运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆