I have created Cmp() function to use as a Comparator.But Iam getting error. I have written this code .It shows error:
#include<bits/stdc++.h>
using namespace std;
struct cmp
{
bool operator() (multimap<int,pair<int,int> > a, multimap<int,pair<int,int> > b)
{
if(a->second.second>b->second.second)
return 1;
return 0;
}
};
int main()
{
std::ios::sync_with_stdio(false);
int test,i;
long long sum=0;
cin>>test;
while(test--)
{
multimap<int, pair<int,int>,cmp > mymap;
multimap<int, pair<int,int> >::iterator it;
int n,days,d,t,s;
cin>>n>>days;
for(i=0;i<n;i++)
{
cin>>d>>t>>s;
mymap.insert(make_pair(d,make_pair(t,s)));
}
for(it=mymap.begin();it!=mymap.end();it++)
{
cout<<it->first<<" "<<it->second.first<<" "<<it->second.second<<endl;
}
}
return 0;
}
It gives error :
In member function 'bool cmp::operator()(std::multimap >, std::multimap >)':
[Error] base operand of '->' has non-pointer type 'std::multimap<int, std::pair<int, int> >'
Is there any other way without using struct Cmp() function?
eg:- suppose i have (3,(2,300)) (3,(1,400)) (3,(2,500)) (2,(3,100)) (2,(2,500)) (1,(5,100)) I want output like this: (1,(5,100)) (2,(2,500)) (2,(3,100)) (3,(2,500)) (3,(1,400)) (3,(2,300)) Only the second element of pair<int,int> sorted decreasingly.