Nested Map,Pair,Vector
#include <bits/stdc++.h>
using namespace std;
int main() {
map<pair<string, string>, vector<int>> m;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string fn, ln;
int x;
cin >> fn >> ln >> x;
for (int j = 0; j < x; j++) {
int y;
cin >> y;
m[{fn, ln}].push_back(y);
}
}
/*for(auto &pr : m) (LUV way)
{
auto &full_name = pr.first;
auto &list = pr.second;
cout << full_name.first << " " << full_name.second << " : ";
for(auto &element : list)
{
cout << element << " ";
}
cout << endl;
}*/
map<pair<string, string>, vector<int>>::iterator it;//Understandable Way
for (it = m.begin(); it != m.end(); it++)
{
cout << it->first.first << " " << it->first.second << " : ";
vector<int>::iterator itr;
for (itr = it->second.begin(); itr != it->second.end(); itr++) {
cout << *itr << " ";
}
cout << endl;
}
return 0;
}
Comments
Post a Comment