You are not logged in. Please login at www.codechef.com to post your questions!

×

unable to find the runtime error here in sums in triangle

/ * To change this template, choose Tools | Templates * and open the template in the editor. / package pract;

/ * @author dell / import java.io.; import java.util.; class SumInTriangle { public static void main(String[] args) throws IOException { Scanner scn=new Scanner(System.in); int tcase=scn.nextInt(); int[] res=new int[tcase];

    for(int k=1;k<=tcase;k++)
    {


    int rows=scn.nextInt();



    int a[][]=new int[rows][];

    for (int i = 0; i < rows; i++) 
    {
        a[i]=new int[i+1];
        for (int j = 0; j < i+1; j++) 
        {
            a[i][j]=scn.nextInt();

        }

    }

    for(int i=rows-2;i>=0;i--)
    {
        for(int j=i;j>=0;j--)
        {
            if(a[i+1][j]>a[i+1][j+1])
                a[i][j]=a[i+1][j]+a[i][j];

            else
               a[i][j]=a[i+1][j+1]+a[i][j];


        }
    }

    res[k-1]=a[0][0];

    }

    for (int i = 0; i < tcase; i++) 
    {


    System.out.println(res[i]);
    }










}

static class Scanner { private final InputStream is; private final byte[] data = new byte[0x2000]; private int next, size;

    public Scanner(InputStream is) {
        this.is = is;
    }




            private boolean read() throws IOException {
        size = is.read(data);
        if (size == 0) {
            int i = is.read();
            if (i < 0)
                return false;
            data[0] = (byte) i;
            size = 1;
        } else if (size < 0)
            return false;
        next = 0;
        return true;
    }

public int nextInt() throws IOException { int r; do { if (next >= size && !read()) throw new EOFException(); r = data[next++]; } while (r < '0' || r > '9'); r -= '0'; for (int d; (next < size || read()) && '0' <= (d = data[next++]) && d <= '9';) r = r * 10 + d - '0'; return r; } } }

asked 26 Feb '14, 03:09

pankaj_427's gravatar image

0★pankaj_427
12
accept rate: 0%

1

you should put a link to your solution instead of the actual code according to the FAQ .

(26 Feb '14, 03:19) muhammedabuali0★

link

answered 26 Feb '14, 08:10

garakchy's gravatar image

1★garakchy
1.1k163048
accept rate: 1%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×545
×231

question asked: 26 Feb '14, 03:09

question was seen: 737 times

last updated: 26 Feb '14, 08:10