In this HackerRank Compare the Triplets problem you have given a and b, determine their respective comparison points.

HackerRank Compare the Triplets problem solution


Problem solution in Python programming.

#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the compareTriplets function below.
def compareTriplets(a, b):
    nas = []
    x=0
    y=0
    for i in range(0,len(a)):

        if a[i]>b[i]:
            x=x+1
        elif b[i]>a[i]:
            y=y+1
        else:
            continue
    nas.append(x)
    nas.append(y)
    return nas

    

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    a = list(map(int, input().rstrip().split()))

    b = list(map(int, input().rstrip().split()))

    result = compareTriplets(a, b)

    fptr.write(' '.join(map(str, result)))
    fptr.write('\n')

    fptr.close()


Problem solution in Java Programming.

import java.io.*;
import java.util.*;

public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
   
    	Scanner scan = new Scanner(System.in);
//    	int N = scan.nextInt();
    	int[] alice = new int[3];
    	int[] bob = new int[3];
    	int a=0, b=0;
    	for(int i=0;i<3;i++)
    		alice[i]=scan.nextInt();
    	for(int i=0;i<3;i++)
    		bob[i]=scan.nextInt();
    	for(int i=0;i<3;i++)
    		if(alice[i]>bob[i])
    			a++;
    		else if(alice[i]<bob[i])
    			b++;
    	System.out.println(a+" "+b);
    	scan.close();
    }
}


Problem solution in C++ programming.

#include <bits/stdc++.h>

template<typename T> T gcd(T a, T b) {
    if(!b) return a;
    return gcd(b, a % b);
}
template<typename T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

template<typename T> void chmin(T& a, T b) { a = (a > b) ? b : a; }
template<typename T> void chmax(T& a, T b) { a = (a < b) ? b : a; }
int in() { int x; scanf("%d", &x); return x; }

using namespace std;

#ifdef ONLINE_JUDGE
#define debug(args...)
#else
#define debug(args...) fprintf(stderr,args)
#endif

typedef long long Int;
typedef unsigned long long uInt;
typedef unsigned uint;

int A[5], B[5];

int main(void) {
    int ia = 0;
    int ib = 0;
    
    for (int i = 0; i < 3; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < 3; i++) {
        cin >> B[i];

        if (A[i] < B[i]) {
            ib += 1;
        } else if (A[i] > B[i]) {
            ia += 1;
        }
    }

    cout << ia << " " << ib << "\n";
    return 0;
}


Problem solution in C programming.

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main(){
    int a0; 
    int a1; 
    int a2; 
    scanf("%d %d %d",&a0,&a1,&a2);
    int b0; 
    int b1; 
    int b2;
    
    int a_score = 0;
    int b_score = 0;
    scanf("%d %d %d",&b0,&b1,&b2);
    if (a0 > b0)
        a_score++;
    else if (a0 < b0)
        b_score++;
    else{}
        //no op
        
    if (a1 > b1)
        a_score++;
    else if (a1 < b1)
        b_score++;
    else {}
        //no op

    if (a2 > b2)
        a_score++;
    else if (a2 < b2)
        b_score++;
    else {}
        //no op
    
    printf("%d %d",a_score, b_score);            
    return 0;
}


Problem solution in JavaScript programming.

process.stdin.resume();
process.stdin.setEncoding('ascii');

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on('data', function (data) {
    input_stdin += data;
});

process.stdin.on('end', function () {
    input_stdin_array = input_stdin.split("\n");
    main();    
});

function readLine() {
    return input_stdin_array[input_currentline++];
}

/////////////// ignore above this line ////////////////////

function main() {
    var a0_temp = readLine().split(' ');
    var a0 = parseInt(a0_temp[0]);
    var a1 = parseInt(a0_temp[1]);
    var a2 = parseInt(a0_temp[2]);
    var b0_temp = readLine().split(' ');
    var b0 = parseInt(b0_temp[0]);
    var b1 = parseInt(b0_temp[1]);
    var b2 = parseInt(b0_temp[2]);
    
    let bScore = 0;
    let aScore = 0;
    
    for(let i = 0; i < a0_temp.length; i++){
        var aProblem = parseInt(a0_temp[i]);
        var bProblem = parseInt(b0_temp[i]);
        if (aProblem > bProblem) {
            aScore++;
        }
        else if (bProblem > aProblem) {
            bScore++;
        }
    }
    
    console.log(`${aScore} ${bScore}`);

}