Saturday, 9 March 2019

 

The Best Player from HackerEarth 
Try here

Approach:


Using c++ stl, pair, sort method



Run and check at  here


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

bool sorting_it(const pair<string,long> &a, const pair<string,long> &b ) {
    
    
    if(a.second!=b.second)
        return (a.second>b.second);
    else
        return(a.first<b.first);
    
}

int main()
{
    long N;
    long T;
    cin>>N>>T;
    string str;
    long q;
    pair<string,long> p[MAX_SIZE];
    for(long i=0;i<N;i++)
    {
        cin>>str>>q;
        p[i]=make_pair(str,q);
    }
    sort(p,p+N,sorting_it);
    for(long i=0;i<T;i++)
    {
       cout<<p[i].first<<endl;
      
    }
    return 0;
}  

No comments:

Post a Comment