Compare the Triplets solution

Problem discussion

          Compare the Triplets needs two integer Array. Each Array will contain 3 integer elements at 0, 1, 2 index respectively. 

Now you just need to compare with the same indexed elements of the Arrays and to determinate how much bigger elements they contain. In this way, Alice and Bob will be awarded points. Suppose A and B are two integer Array so:

  • If A[index] > B[index], then Alice is awarded 1 point.
  • If A[index] < B[index], then Bob is awarded 1 point.
  • If A[index] = B[index], then neither person receives a point.

For example, lets we check an input sample.

Sample Input

5 6 7
3 6 10

Sample Output

1 1

Here,
A[0] > B[0], so Alice is awarded 1 point
A[1] = B[1], so no one receives any point.
A[2] < B[2], so Bob is awarded 1 point.
So the solution is Alice gets total 1 point and Bob gets total 1 point and this is the output.

Now try to solve the problem. If you still get failed to solve the problem, just look at the below code and try again but please don’t copy the code, it is dangerous for your progress. 

Source code

Before seeing the source code ensure that you have tried hard most!!! 
#include<cstdio>

int main()
{
    int a[3];
    int b[3];

    for(int index = 0; index < 3; index++)
        scanf("%d", &a[index]);
    for(int index = 0; index < 3; index++)
        scanf("%d", &b[index]);

    int a_score = 0;
    int b_score = 0;

    for(int index = 0; index < 3; index++)
    {
        if(a[index] > b[index])
            a_score++;
        else if(a[index] < b[index])
            b_score++;
    }

    printf("%d %d\n",a_score, b_score);


    return 0;
}
Be with us, stay happy. Please do your precious comment and give an opportunity to improve us.

Happy coding.

Leave a comment

Website Powered by WordPress.com.

Up ↑

Design a site like this with WordPress.com
Get started