Thursday, September 17, 2015

Sum It Up (Mock KICTM UiTM Jasin 2015)

The input begins with an integer K (0<=K<=100) which denotes the numbers of the test cases. This line is followed by K lines with a list of integers. The first value, N (1<=N <= 50), indicates the numbers of integers for the list, followed by N integers with value more than 0 ans less then 999999.

Sample input
2
4 3 2 1 1
3 4 5 5

Samples Output
7
14


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.*;
import java.lang.*;
import java.math.*;

public class Mock1{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      
      String line =System.getProperty("line.separator");
      scan.useDelimiter(line);
      
      int cases = scan.nextInt();
      
      for(int x=0;x<cases;x++){
         
         String [] get = scan.next().split(" ");
         
         int total=0;
         for(int y=1;y<get.length;y++){
            total = total + Integer.parseInt(get[y]);
         }
         
         System.out.println(total);
         
      }
   }
}

No comments:

Post a Comment