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<string, int> a, pair<string, int> b){return a.second > b.second;}void dedicationLevel(int n, vector<pair<string, int>> &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<string, int>> v = {{"Darshan", 78},{"Harshad", 90},{"Jaimin", 87},{"Nirav", 88},{"Hardik", 1},{"Fenil", 70},{"Lovlin", 5}};dedicationLevel(n, v);return 0;}
No comments:
Post a Comment