Monday, June 29, 2015

Solve me second

Problem Statement

This is the second challenge in the introduction series. The purpose of this challenge is to give you a working I/O template in your preferred language. It includes scanning two space-separated integers from STDIN in a loop over T lines, calling a function, returning a value, and printing it to STDOUT.
A pseudo code looks like the following:
read T
loop from 1 to T
    read A and B
    compute the sum
    print value in a newline
end loop
Input Format

The first line contains T (number of test cases) followed by T lines
Each line contains A and B, separated by a space.
As you can see that we have provided in advance the number of lines, we discourage the use of scanning till EOF as not every language has an easy way to handle that. In fact, every HackerRank challenge is designed in such a way that multitests begin with a T line to indicate the number of lines.

Sample Input
2 3
3 7
Sample Output

import java.util.*;

class Solution
       static int solveMeSecond(int a, int b)
        return a+b;

        public static void main(String[] args)
            Scanner in = new Scanner(;
            int t;
            int sum;
            int a,b;
            t = in.nextInt();
            for (int i=0;i<t;i++)
                a = in.nextInt();
                b = in.nextInt();
                sum = solveMeSecond(a, b);


Post a Comment