Hi,

We will start to solve another problem set with easy level. This problem is about comparing input values  from user, here is the problem.

Compare the Triplets

Alice and Bob compete each other for creating challenges. A judge rates the two of them as challenger, then awarding points on a scale from 1 to 100  for three categories: problem clarity (c0), originality (c1), and difficulty (c2).

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 computes award point then compare of both (Alice’s & Bob’s) points they got

  • if(ai > bi) then Alice rewarded for 1 point.
  • if(ai < bi) then Bob rewarded for 1 point.
  • if(ai = bi) then neither of them awarded

Input format

The first line contains 3 space-separated integers a0, a1, and a2 describing the respective values in triplet of Alice’s.
The second line contains 3 space-separated integers b0, b1, and b2 describing the respective values in triplet of Bob’s.

Constraint

1<= ai <= 100
1<= ai <= 100

Output format

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

Sample Input

4 8 9
4 9 9

Sample Output

0 1 -> contain whitespace between value

Explanation

Each of triplets input defined by c0, c1, c2 which ‘c’ is categories. In example:

A = (a0, a1, a2) = (4, 8, 9)
B = (b0, b1, b2) = (4 9 9)

Then, let’s compare each indivisdual value:

a0 = b0 so neither of them got point (0 0)
a1 < b0 so Bob get 1 point (0 1)
a2 = b2 so neither of them get point (0 1)

Alice’s point is 0 and Bob’s point is 1. So we print 0 1 (Alice’s point comparison followed by Bob’s point).

Here is the solution of mine


public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a0 = in.nextInt();
        int a1 = in.nextInt();
        int a2 = in.nextInt();
        int b0 = in.nextInt();
        int b1 = in.nextInt();
        int b2 = in.nextInt();
        
        int pointA = ((a0>b0)?1:0)+((a1>b1)?1:0)+((a2>b2)?1:0);
        int pointB = ((a0<b0)?1:0)+((a1<b1)?1:0)+((a2<b2)?1:0);
        
        System.out.print(pointA+" "+pointB);
    }
}

Simply implementation using checking condition statements with form (checking condition)?true value:false value. Because the problem here comparing score / point of each value, so I give operator ‘+‘ then print like format in sample output.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s