在UVA在线评测运行时错误 [英] Runtime error in UVA Online Judge

查看:290
本文介绍了在UVA在线评测运行时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做题10003切枝的弗吉尼亚网上法官,我是pretty的肯定,我的code的作品,我想我正确地退出的问题。但我仍得到一个运行时错误,我读的地方,是因为我不退出应用程序,如我应该做的。我希望你们能帮助我解决这个问题。

 进口java.io. *;
类主要{

    静态INT LEN,C,分钟;
    静态INT垫[] [] =新INT [52] [52];
    静态INT ARR [] =新的INT [52];
    静态的BufferedReader BufferReader =新的BufferedReader(新的InputStreamReader(System.in));
    公共静态无效llenaarr()抛出IOException异常{
            的for(int i = 0;我c为C-1;我++){
                    改编[I + 1] =的Integer.parseInt(BufferReader.readLine());
                    }
            改编[0] = 0;
            ARR [C] = LEN;
            }
    公共静态无效llenamat(){
            的for(int i = 0; I< = C;我++){
                    对于(INT J = 0; J< = C,J ++){
                            垫[I] [J] = Integer.MAX_VALUE的;
                            }
                    }
            的for(int i = 0;我c为C;我++){
                    垫[I] [I] = 0;
                    垫[I] [I + 1] = 0;
                    }
            垫[C] [C] = 0;
            的for(int i = 0;我c为C-1;我++){
                    垫[I] [I + 2] =改编[I + 2]  - 常用3 [I]
                    }
            }
    公共静态无效MINIMO(){
            对于(INT K = 3; K< = C; k ++){
                    的for(int i = 0; I< = C-K;我++){
                            对于(INT J = I + 1; J< = I + K-1,J ++){
                                    分=垫[I] [J] +垫[j]的[I + K] +改编[I + K]  - 常用3 [I]
                                    如果((分钟<垫[I] [I + K])){
                                            垫[I] [I + K] =分钟;
                                            }
                                    }
                            }
                    }
            }

    公共静态无效的主要(字符串的args [])抛出IOException异常{
            而((LEN =的Integer.parseInt(BufferReader.readLine()))大于0){
                    C =(的Integer.parseInt(BufferReader.readLine()))+ 1;

                    llenaarr();
                    llenamat();
                    MINIMO();
                    的System.out.println(最小切割+垫[0] [C] +。);
                    }
            }
    }
 

解决方案

处理输入过程中,你的程序是抛出某种运行时异常的。为了验证这一点,您应该封装的code在try-catch块(即运行在输入和输出产生的部分)。

要努力赶上的第一件事就是一般的异常。这将捕捉任何类型的运行时异常。通过网上法官再次运行它,你现在应该看到一个错误的答案结果(假设事情不处理吧,因为它毕竟是抛出一个异常)。

现在来侦破工作。回到你的源$ C ​​$ C,看看你制作和使用的API文档,检查所有他们可能会引发可能的异常呼叫。例如,如果你调用的Integer.parseInt(inputString),它可能是抛出一个NumberFormatException异常。所以,上面的你赶上(例外五)块,开始加入​​一些你认为可能会导致问题更加具体的例外。

在理想情况下(如果你有时间和耐心),你会希望每一个之后添加这些一次,并重新提交到网上的法官。当结果来自错误答案回运行时错误动作,你就会知道你已经发现,是导致问题的例外。从这里,希望这将有助于你缩小东西把重点放在(修复)在源$ C ​​$ C解决方案。

祝你好运。

I'm doing problem 10003 "cutting sticks" of the UVa online judge, I'm pretty sure my code works and I think I' correctly exiting the problem. But still I get a runtime error, I read somewhere that is because I'm not exiting the application like I'm supposed to do it. I wish you guys can help me with this problem.

import java.io.*;
class MAIN {

    static int len, c, min;
    static int mat[][] = new int[52][52];
    static int arr[] = new int [52];
    static BufferedReader BufferReader = new BufferedReader(new InputStreamReader(System.in));
    public static void llenaarr()throws IOException{
            for(int i=0; i<c-1; i++) {
                    arr[i+1] = Integer.parseInt(BufferReader.readLine());
                    }
            arr[0] = 0;
            arr[c] = len;
            }
    public static void llenamat(){
            for(int i=0; i<=c; i++) {
                    for(int j=0;j<=c;j++) {
                            mat[i][j] = Integer.MAX_VALUE;
                            }
                    }
            for(int i=0; i<c; i++) {
                    mat[i][i] = 0;
                    mat[i][i+1] = 0;
                    }
            mat[c][c] = 0;
            for(int i=0; i<c-1; i++) {
                    mat[i][i+2] = arr[i+2] - arr[i];
                    }
            }
    public static void minimo(){
            for(int k=3; k<=c; k++) {
                    for(int i=0; i<=c-k; i++) {
                            for(int j=i+1; j<=i+k-1; j++) {
                                    min=mat[i][j] + mat[j][i+k] + arr[i+k] - arr[i];
                                    if((min< mat[i][i+k])) {
                                            mat[i][i+k] = min;
                                            }
                                    }
                            }
                    }
            }

    public static void main (String args[]) throws IOException {
            while((len = Integer.parseInt(BufferReader.readLine())) > 0){
                    c = (Integer.parseInt(BufferReader.readLine()))+1;

                    llenaarr();
                    llenamat();
                    minimo();
                    System.out.println("The minimum cutting is "+mat[0][c]+".");
                    }
            }
    }

解决方案

Your program is throwing some kind of runtime Exception during processing input. To verify this, you should encapsulate your code (the part that operates on the input and produces output) in a try-catch block.

The first thing to try to catch is the generic Exception. This will catch any type of runtime exception. Run it through the online judge again, and you should now see a Wrong Answer result (assuming something is not processing right, because it is throwing an exception after all).

Now comes the detective work. Go back to your source code and look at all the calls you make and use the API Docs to check all the possible exceptions they may throw. For example, if you call Integer.parseInt(inputString), it may be throwing a NumberFormatException. So above your catch (Exception e) block, start adding some more specific exceptions you think may be causing the problem.

Ideally (if you have the time and patience) you'll want to add these one at a time and resubmit to the online judge after each one. When the result moves from Wrong Answer back to Runtime Error, you'll know you've found the exception that is causing the problem. From here, hopefully this will help you narrow down what to focus on (to fix) in your source code solution.

Good luck.

这篇关于在UVA在线评测运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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