题解:
#include <bits/stdc++.h>
using namespace std;
map<string, vector<string>> mp;//使用一个第二个元素可以存字符数组的map
vector<string> citys;
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int N;cin >> N;
for(int i = 0; i < N; i++)
{
string a,b;cin >> a >> b;
if(!mp.count(b))citys.push_back(b);
mp[b].push_back(a);
}
for(const auto &city: citys)
{
cout << city << ' ' << mp[city].size() << "\n";//是size不是length
for(const auto &i: mp[city])
{
cout << i << '\n';//遍历map的vector
}
}
return 0;
}