Sorting on pair of vector with first element doesnt work C++
I'm trying to solve a question : QUESTION
So in order to solve it I must sort the pair of vector but when I try'a do it,It doesn't work, So how to fix it? MY Code
#include <iostream>
#include <vector>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie();
cout.tie();
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int TestCase;
cin>>TestCase;
while(TestCase--){
int HardDisk,Total;
vector<pair<int,int>>Data;
cin>>Total>>HardDisk;
while(Total--){
int IMDB,Size;
cin>>Size>>IMDB;
Data.push_back(make_pair(Size,IMDB));
}
sort(Data.begin(),Data.end());
for(int i=0;i<Data.size();i++){
cout<<Data[i].first<<" "<<Data[i].second<<endl;
}
}
}
from Recent Questions - Stack Overflow https://ift.tt/3d9yxHW
https://ift.tt/eA8V8J
Comments
Post a Comment