Dedication Level = Infinity

These are the people from nirmaLand who have shown utmost dedication towards Competitive Programming..!

You will be provided with the name of the coder and no. of hours he/she spent on coding.

You need to output the top 3 names of the coders who spent the most time in coding.

Note: Time (no. of hours) given for all coders will be unique. More technically, no two coders will have the same amount of time.

Example:

Input:  n = 7, v = {{"Darshan", 78}, {"Harshad", 90}, {"Jaimin", 87}, {"Nirav", 88}, {"Hardik", 1}, {"Fenil", 70}, {"Lovlin", 5}}

Output:

Harshad Nirav Jaimin

Approach:

C++

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

bool cmp(pair<stringintapair<stringintb)
{
    return a.second > b.second;
}

void dedicationLevel(int nvector<pair<stringint>> &v)
{

    sort(v.begin(), v.end(), cmp);
    cout << v[0].first << "\n";
    cout << v[1].first << "\n";
    cout << v[2].first << "\n";
}
int main()
{
    int n = 7;
    vector<pair<stringint>> v = {{"Darshan"78},
                                   {"Harshad"90},
                                   {"Jaimin"87},
                                   {"Nirav"88},
                                   {"Hardik"1},
                                   {"Fenil"70},
                                   {"Lovlin"5}};

    dedicationLevel(nv);

    return 0;
}


No comments:

Post a Comment