Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在线判断在URI处获取java中可能的运行时错误_Java_String_Exception_Runtime Error - Fatal编程技术网

在线判断在URI处获取java中可能的运行时错误

在线判断在URI处获取java中可能的运行时错误,java,string,exception,runtime-error,Java,String,Exception,Runtime Error,我试图在URI在线判断时解决一个问题,但可能出现运行时错误。我试图找出错误,但无法理解代码在哪里生成异常。我知道这是因为我在代码中获取输入,而不是在查找lcs的部分 如果有人能告诉我哪里有错误,或者任何这样的测试用例证明了这个错误,那将是非常有帮助的 解决了这个问题。由于URI online judge的输入文件中有额外的空格,我得到了可能的运行时错误。 br.readLine.trim没有使用br.readLine,而是解决了我的问题。您能提供异常的堆栈跟踪吗?这是生成最长公共子序列的一部分。

我试图在URI在线判断时解决一个问题,但可能出现运行时错误。我试图找出错误,但无法理解代码在哪里生成异常。我知道这是因为我在代码中获取输入,而不是在查找lcs的部分

如果有人能告诉我哪里有错误,或者任何这样的测试用例证明了这个错误,那将是非常有帮助的


解决了这个问题。由于URI online judge的输入文件中有额外的空格,我得到了可能的运行时错误。
br.readLine.trim没有使用br.readLine,而是解决了我的问题。

您能提供异常的堆栈跟踪吗?这是生成最长公共子序列的一部分。但它不会导致任何错误,因为我尝试提交最后两个for循环的注释。在上一次迭代中,它将比较fir[i-1]第一个字符串的最后一个字符和第二个字符串的所有字符我没有堆栈跟踪,因为我不知道我的代码在哪里失败。但是当我提交此代码时,我在URI online上可能会遇到运行时错误judge@aa1992你能提供stacktrace吗?把你的代码放在try catch中,然后打印stacktrace@singhakash我理解你在说什么。我尝试打印堆栈跟踪,但在我提供输入时,我的代码中没有出现异常。但是,当我将代码提交到URI时,我可能会出现运行时错误。那么,当我没有收到任何异常时,我如何向你提供堆栈跟踪。当我提供输入时,我的代码运行得非常完美
package URI;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class KidsGrid {


    public static void main(String[] args) throws NumberFormatException, IOException{
    // TODO Auto-generated method stub
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
        String s;
        StringTokenizer st;
        int T;          
        int caser=1;
        T=Integer.parseInt(br.readLine().trim());
        while(T>0)
        {
            String first="",second="";
            char fir[],sec[];
            fir=sec=null;
            if((s=br.readLine())!=null)
            {
                s=s.trim();                     
                st=new StringTokenizer(s);                  
                int H=Integer.parseInt(st.nextToken());
                int W=Integer.parseInt(st.nextToken());
                char arr[][]=new char[H+1][W+1];
                for(int i=1;i<=H;)
                {
                    if((s=br.readLine())!=null)
                    {
                        for(int j=1;j<=W;j++)
                        {
                            arr[i][j]=s.charAt(j-1);
                        }
                        i++;
                    }
                }

                if((s=br.readLine())!=null)
                {
                    s=s.trim();
                    st=new StringTokenizer(s);          
                    int N=Integer.parseInt(st.nextToken());
                    int x=Integer.parseInt(st.nextToken());
                    int y=Integer.parseInt(st.nextToken());
                    first+=arr[x][y];
                    if(N>0&&(s=br.readLine())!=null)
                    {
                        s=s.trim();                             
                        for(int i=1;i<=N;i++)
                        {

                            switch(s.charAt(i-1))
                            {
                                case 'N':
                                x--;
                                break;
                                case 'S':
                                x++;
                                break;
                                case 'W':
                                y--;
                                break;
                                case 'E':
                                y++;
                                break;
                            }
                            first+=arr[x][y];

                        }
                        first=first.trim();
                        fir=first.toCharArray();
                    }
                }


                if((s=br.readLine())!=null)
                {
                    s=s.trim();
                    st=new StringTokenizer(s);          
                    int N=Integer.parseInt(st.nextToken());
                    int x=Integer.parseInt(st.nextToken());
                    int y=Integer.parseInt(st.nextToken());
                    second+=arr[x][y];
                    if((s=br.readLine())!=null)
                    {
                        s=s.trim();
                        for(int i=1;i<=N;i++)
                        {

                            switch(s.charAt(i-1))
                            {
                                case 'N':
                                x--;
                                break;
                                case 'S':
                                x++;
                                break;
                                case 'W':
                                y--;
                                break;
                                case 'E':
                                y++;
                                break;
                            }
                            second+=arr[x][y];

                        }
                        second=second.trim();
                        sec=second.toCharArray();

                    }
                }                                           

                if(sec!=null && fir!=null)
                {
                    int lcs[][]=new int[fir.length+1][sec.length+1];
                    for(int i=0;i<=fir.length;i++)
                    {
                        for(int j=0;j<=sec.length;j++)
                        {
                            if(i==0||j==0)
                                lcs[i][j]=0;
                            else if(fir[i-1]==sec[j-1])
                                lcs[i][j]=lcs[i][j-1]+1;
                            else
                                lcs[i][j]=Math.max(lcs[i][j-1],lcs[i-1][j]);

                        }

                    }
                        //System.out.println("Common"+ lcs[fir.length][sec.length]);
                    int a=fir.length-lcs[fir.length][sec.length];
                    int b=sec.length-lcs[fir.length][sec.length];
                    System.out.println("Case "+caser+": "+a+" "+b);
                    caser++;
                    T--;
                }
                        //System.out.println("T="+T);
            }
        }
    }
}