# HackerRank : ACM ICPC Practice Contest 2016 – Compare the Triplets

By | November 27, 2016

Alice and Bob each created one problem for HackerRank. A reviewer rates the two challenges, awarding points on a scale from 1 to 100 for three categories: problem clarity, originality, and difficulty.

We define the rating for Alice’s challenge to be the triplet A=(a0,a1,a2), and the rating for Bob’s challenge to be the triplet B=(b0,b1,b2) .

Your task is to find their comparison scores by comparing a0 with b0,  a1 with b1, and a2 with b2.

• If ai>bi, then Alice is awarded 1 point.
• If ai<bi, then Bob is awarded 1  point.
• If ai=bi, then neither person receives a point.

Given A and B , can you compare the two challenges and print their respective comparison points?

Input Format

The first line contains 3 space-separated integers, a0, a1 , and a2, describing the respective values in triplet A.
The second line contains 3 space-separated integers, b0, b1 , and b2, describing the respective values in triplet B.

Output Format

Print two space-separated integers denoting the respective comparison scores earned by Alice and Bob.

Sample Input

5 6 7
3 6 10


Sample Output

1 1


Explanation

In this example:

A= (a0,a1,a2)=(5,6,7)

B= (b0,b1,b2)=(3,6,10)

Now, let’s compare each individual score:

• a0>bo, so Alice receives 1 point.
• a1=b1, so nobody receives a point.
• a2<b2, so Bob receives 1 point.

Alice’s comparison score is 1, and Bob’s comparison score is 1. Thus, we print 1 1 (Alice’s comparison score followed by Bob’s comparison score) on a single line.

Solution

Take all inputs for a and b.
Compare the first of a's and b's and if a0>b0 then, increase count of a, else
increase count of b, if they are same then dont increase count of a or b.
Repeat the process of next of a's and b's. i.e a1 and b1.. and a2 and b2.

Code:

package aCMICPCPracticeContest2016;

import java.util.Scanner;

public class CompareTheTriplets {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

int a0, a1, a2, b0, b1, b2 = 0;
int a = 0, b = 0;

a0 = scan.nextInt();
a1 = scan.nextInt();
a2 = scan.nextInt();
b0 = scan.nextInt();
b1 = scan.nextInt();
b2 = scan.nextInt();

if (a0 == b0) {
a = a + 0;
b = b + 0;
} else if (a0 > b0)
a = a + 1;
else
b = b + 1;

if (a1 == b1) {
a = a + 0;
b = b + 0;
} else if (a1 > b1)
a = a + 1;
else
b = b + 1;

if (a2 == b2) {
a = a + 0;
b = b + 0;
} else if (a2 > b2)
a = a + 1;
else
b = b + 1;

System.out.println(a + " " + b);
}

}