ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1100. Final Standings

1100 Final Standings Solved Using C++ STL Vector , Pair And stable_sort
Posted by Ashadullah Shawon 11 Jun 2016 01:54
Here is my Solution. As this problem is related to stable sort and there is  built in stable_sort function in c++ so it has become easier


#include <bits/stdc++.h>
using namespace std;
bool compare( const pair<long long int,long long int>& x, const pair<long long int, long long int>& y )
{

    return (x.second>y.second);

}
int main()
{
    vector<pair<long long int,long long int> >a;
    long long int n,i,j,b,c;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>b>>c;
        a.push_back(pair<long long int,long long int>(b,c));
    }
    stable_sort(a.begin(),a.end(),compare); //must include stable_sort
    vector<pair<long long int,long long int> >::iterator p;
    for(p=a.begin();p!=a.end();p++)
    {
        cout<<p->first<<" "<<p->second<<endl;
    }
    return 0;



}

Edited by author 11.06.2016 01:55