Compare the Triplet

Alice and Bob each created one problem for HackerRank. A reviewer rates the two challenges, awarding points on a scale from to for three categories: problem clarity, originality, and difficulty.
We define the rating for Alice's challenge to be the triplet , and the rating for Bob's challenge to be the triplet .
Your task is to find their comparison scores by comparing with , with , and with .
  • If , then Alice is awarded point.
  • If , then Bob is awarded point.
  • If , then neither person receives a point.
Given and , can you compare the two challenges and print their respective comparison points?


Solution : 

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int alice=0;
        int bob=0;
        int a0 = in.nextInt();
        int a1 = in.nextInt();
        int a2 = in.nextInt();
        int b0 = in.nextInt();
        int b1 = in.nextInt();
        int b2 = in.nextInt();
       
        if (a0<b0){
            bob+=1;
           
        }
        if (a1<b1){
            bob+=1;
           
        }
        if (a2<b2){
            bob+=1;
          
        }
        if(a0>b0 ){
            alice+=1;
          
           
        }
        if(a1>b1 ){
            alice+=1;
           
           
        }
        if(a2>b2){
            alice+=1;
           
           
        }
        if(a0==b0){
            alice+=0;
           bob+=0;         
          
        }
        if(a1==b1){
            alice+=0;
           bob+=0;         
          
        }
        if(a2==b2){
            alice+=0;
           bob+=0;         
          
        }
        System.out.println(alice+" "+bob);
    }
}

5 Comments

  1. Isn't there a faster way to do this?

    ReplyDelete
    Replies
    1. void compare(int alice[],int bob[])
      {
      int acount=0;
      int bcount=0;
      int i;
      for(i=0;i<3;i++)
      {
      if(alice[i]>bob[i])
      {
      acount++;
      }
      if(alice[i]<bob[i])
      {
      bcount++;
      }

      }
      cout<<acount<<" "<<bcount;

      }

      Ez method!

      Delete
  2. Sir any other method or if i take array then can i solve it or not

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
Previous Post Next Post