Weighing the Stones

Rupam and Ankit are both fonds of collecting stones. They both follow this hobby diligently and go out to find stones together. So, one fine day they decided to play a small game. They decided to weigh each of the stones and note them down in a notepad, and then at the end of the day, both of them will compare their notes.


They will check how many stones of a particular weight are there. Then they will compare the weight of the stone occurring a maximum number of times (you can consider stones of similar weight to be similar). In case that all different stones occur the exactly the same number of times, the stone with maximum weight will be considered for comparison. The person with the higher weighing stone wins, else there will be a tie. You need to determine the result.

Example:

Input:  n = 6, a = [5,3,1,4,3,2], b = [4,3,1,1,1,5]
Output: Rupam

Approach

C++

#include <bits/stdc++.h>
using namespace std;

void weighingTheStones(int nint a[], int b[])
{
    int f[100] = {0}, f1[100] = {0};
    for (int i = 0i < ni++)
        f[a[i]]++;
    for (int i = 0i < ni++)
        f1[b[i]]++;
    int max1 = INT_MIN;
    int xy;
    for (int i = 0i < 100i++)
    {
        if (f[i] >= max1)
        {
            max1 = f[i];
            x = i;
        }
    }
    max1 = INT_MIN;
    for (int i = 0i < 100i++)
    {
        if (f1[i] >= max1)
        {
            max1 = f1[i];
            y = i;
        }
    }
    if (x > y)
        cout << "Rupam\n";
    else if (x == y)
        cout << "Tie\n";
    else
        cout << "Ankit\n";
}
int main()
{

    int n = 6;

    int a[n] = {531432};
    int b[n] = {431115};

    weighingTheStones(nab);

    return 0;
}


No comments:

Post a Comment