ACM Mr. Li Criteria





Problem Link: http://acm.epoka.edu.al:8888/en/problem-pid-c7b3?ps=1&smt=9&smpwid=0

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

bool comparename( const pair<string,long long int>& x, const pair<string, long long int>& y )
{
    if(x.first.size()==y.first.size())
    {
        if(x.second==y.second)
        {
            return x.first<y.first;
        }
       return x.second<y.second;
    }
    return x.first.size()<y.first.size();

}

int main()
{
    vector<pair<string,long long int> >a;
    set<pair<string,long long int> >myset;
    vector<string>ss;
    vector<long long int>gd;
    long long int n,i,j,b,c,cnt=0,l,sh;
    string s;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin>>n>>sh;
    for(i=1;i<=n;i++)
    {
        cin>>s>>c;
        a.push_back(make_pair(s,c));
    }

    sort(a.begin(),a.end(),comparename);

    vector<pair<string,long long int> >::iterator p;

    for(p=a.begin();p!=a.end();p++)
    {
        if(cnt==sh)
        {
            break;
        }
        cout<<p->first<<" "<<p->second<<endl;
        cnt++;

    }


    return 0;


}

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment