0

I always get an error when i try to push back the map's value to the vector also when i try to output the vector's value.

#include<bits/stdc++.h> using namespace std; #define pb push_back #define ll int #define mod 1000 #define for1(i,k,n) for(int i=k;i<n;i++) #define for2(k,n) for(int j=k;j<n;j++) #define E cout<<endl #define maxn 10001 bool cmp(pair<ll, ll> &a, pair<ll, ll> &b) { return a.second < b.second; } int main() { ////////////////////////////////////// start................. ll t; cin >> t; while (t--) { ll n; cin >> n; ll arr[n + 1]; map<ll, ll> m; for1(i, 0, n) { cin >> arr[i]; m[arr[i]]++; } vector < pair<ll, ll> > v; for (auto i = m.begin(); i != m.end(); i++) v.pb(i); sort(v.begin(), v.end(), cmp); for (auto i = v.begin(); i != v.end(); i++) cout << i.second << " "; cout << endl; } /////////////////////////////////end................................... .... return 0; }

1st Sep 2020, 11:54 AM
Morningstar
Morningstar - avatar
1 ответ