nested map and imp ques

 #include<bits/stdc++.h>

using namespace std;
#define shailesh ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define rep(i, a, b) for(int i=a; i<b; ++i)
#define ff first
#define ss second


int main(){
   shailesh
   
   map<pair<string, string>, vector<int>> m;
   int n;
   cin>>n;
   rep(i, 0, n){
       string fn, ln;
       int ct;
       cin>>fn>>ln>>ct;
       rep(j, 0, ct){
           int x;
           cin>>x;
           m[{fn, ln}].push_back(x);
       }
   }

   for(auto &pr: m){
       auto &full_name=pr.first;
       auto &list=pr.second;
       cout<<full_name.first<<" "<<full_name.second<<endl;
       cout<<list.size()<<endl;
   
       for(auto &element: list){
           cout<<element<<" ";
       }
       cout<<endl;
       
   }


return 0;
}

// input
3 a b 4 1 2 3 4 c d 2 1 2 d f 3 2 3 4

// output
a b
4
1 2 3 4 
c d
2
1 2 
d f
3
2 3 4

Comments

Popular posts from this blog

priority_queue

My first website