Search This Blog

Saturday, April 19, 2014

Algorithms - Discrete Mathematics - Handshake

Handshake

The following is the solution to Hacker Rank problem Handshake using Java.  For solutions to other Hacker Rank Problem visit my page HackerRank, alternatively try searching for the problem in my blog.

Score:5/5
/**
 *
 */


import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author Arun.G
 *
 */
public class Solution{

       /**
        * @param args
        */
       static BufferedReader in = new BufferedReader(new InputStreamReader(
                     System.in));

       public static void main(String[] args) throws NumberFormatException,
                     Exception {
             
              int T = Integer.parseInt(in.readLine());
       
        for(int i=0;i<T;i++)
          {
          int numofPersons = Integer.parseInt(in.readLine());
          System.out.println((int)(numofPersons*(numofPersons-1))/2);
        }
       
        in.close();
             
             

       }
}

No comments:

Post a Comment

Labels