|
|
back to boardWhat is the wrong in this code?? //URAL-1100-FINAL STANDINGS //--------------------------------- #include<bits/stdc++.h> using namespace std; #define endl '\n' bool comp(pair<int,int>a,pair<int,int>b) { return a.second>b.second; } void sortt(map<int,int>mp) { vector<pair<int,int>>v; for(auto it:mp) { v.push_back(it); }
stable_sort(v.begin(),v.end(),comp); for(auto it:v) { cout<<it.first<<" "<<it.second<<endl; } } int main() { map<int,int>mp; int n; cin>>n; for(int i=0; i<n; i++) { int x,y; cin>>x>>y; mp[x]=y; } sortt(mp); return 0; } Re: What is the wrong in this code?? You are expecting the map to preserve the order. It does not - it sorts by key. Try using unordered_map<int, int> mp |
|
|