Compare the Triplets:
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= (\( a_0,a_1,a_2 \)) and the rating for Bob’s challenge to be the triplet B= (\( b_0,b_1,b_2 \)) Your task is to find their comparison scores by comparing \( a_0 \) with \(a_1 \) , \( a_1\) with \( b_1\) and \( a_2 \)with \( b_2\)
- if \( a_i\)>\(b_i\) , then Alice is awarded 1 point.
- if \( a_i\)<\(b_i\) , then Bob is awarded 1 point.
- if \( a_i\)=\(b_i\) , 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 \( a_0,a_1 and a_2 \), describing the respective values in triplet A
The second line contains 3 space-separated integers,\( b_0,b_1 and b_2 \) , describing the respective values in triplet B
Constraints
- 1 <= (\(a_i)\) <= 100
- 1 <= (\(b_i)\) <= 100
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= (\( a_0,a_1,a_2 \))=(5,6,7)
-
B= (\( b_0,b_1,b_2 \))=(3,6,10) Now, let’s compare each individual score:
- (\(a_0)\) > (\(b_0)\) , so Alice receives 1 point.
- (\(a_0)\) = (\(b_0)\), so nobody receives a point.
- (\(a_0)\) < (\(b_0)\) , 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
Python
#!/bin/python
import sys
def compare_the_score(a, b):
score_a = 0
score_b = 0
for i in range(len(a)):
if a[i] > b[i]:
score_a += 1
elif a[i] < b[i]:
score_b += 1
return score_a, score_b
a0,a1,a2 = raw_input().strip().split(' ')
a = [int(a0),int(a1),int(a2)]
b0,b1,b2 = raw_input().strip().split(' ')
b = [int(b0),int(b1),int(b2)]
print('%d %d' % compare_the_score(a,b))
Bash
a=0
b=0
read -a A_arr
read -a B_arr
for i in $( seq 0 2 ); do
eval a$i=${A_arr[$i]}
eval b$i=${B_arr[$i]}
if (( $(echo $((a$i))) > $(echo $((b$i))) )); then
(( a+=1 ))
elif (( $(echo $((a$i))) < $(echo $((b$i))) )); then
(( b+=1 ))
fi
done
echo $a $b
comments powered by Disqus