Triangle Sum

Let's consider a triangle of numbers in which a number appears in the first line, two numbers appear in the second line, three in the third line, etc. Develop a program which will compute the least of the sums of numbers that appear on the paths starting from the top towards the base, so that:
 on each path the next number is located on the row below, more precisely either directly below or below and one place to the right;
 the number of rows is strictly positive, but less than 100
 all numbers are positive integers between O and 99.
Input
In the first line integer n  the number of test cases (equal to about 1000).
Then n test cases follow. Each test case starts with the number of lines which is followed by their content.
Output
For each test case write the determined value in a separate line.
Example
Input: 2 3 1 2 1 1 2 3 4 1 1 2 4 1 2 2 3 1 1 Output: 4 4
Code
#include <iostream> using namespace std;int main() { int a[99][99]; int n,t; cin>>t; while(t) { cin>>n; for(int i=0;i<n;i++) { for(int j=0;j<=i;j++) { cin>>a[i][j]; } } for(int i=n2;i>=0;i) { for(int j=0;j<=i;j++) { if(a[i+1][j]<a[i+1][j+1]) { a[i][j]=a[i][j]a[i+1][j]; } else { a[i+1][j]=a[i][j]+a[i+1][j+1]; } } } cout<<a[0][0]<<endl; } return 0; }
Steps to be followed
1. Read the given description carefully and understand the problem.
2. Analyze the code given in the problem and find bugs(errors) in these codes..
3. The given code can be copied and compiled in an online compiler (Eg. ideone.com).
4. Once the bugs are eliminated from the code, the clean code can be submitted as the solution to the problem..
5. The solution should be a debugged version of the code provided and must satisfy the test cases to be accepted..
All the best!!
Author:  sneha_rajeev 
Tags  sneha_rajeev 
Date Added:  21012016 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages: 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions