FRom hackerrank
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 points 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.
Comparison points is the total points a person earned.
Given and , determine their respective comparison points.
For example, and . For elements , Bob is awarded a point because . For the equal elements and , no points are earned. Finally, for elements , so Alice receives a point. Your return array would be with Alice's score first and Bob's second.
Solution in C# -
class Solution {
static List<int> compareTriplets(List<int> a, List<int> b) {
List<int> results = new List<int>(){0,0};
for(int i=0;i<3;i++)
{
if(a[i] > b[i])
results[0]++;
else if(a[i] == b[i])
continue;
else
results[1]++;
}
return results;
}
static void Main(string[] args) {
TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
List<int> a = Console.ReadLine().TrimEnd().Split(' ').ToList().Select(aTemp => Convert.ToInt32(aTemp)).ToList();
List<int> b = Console.ReadLine().TrimEnd().Split(' ').ToList().Select(bTemp => Convert.ToInt32(bTemp)).ToList();
List<int> result = compareTriplets(a, b);
textWriter.WriteLine(String.Join(" ", result));
textWriter.Flush();
textWriter.Close();
}
}
Post a Comment