#include <iostream>
#include <map>
#include <sstream>
#include <vector>
// simulate the file:
std::istringstream in(
R"(Driver1 3
Donkey11 4 500 800 1200 450
Donkey12 3 800 700 600
Donkey13 5 120 150 200 500 300
Driver2 2
Donkey21 3 910 220 410
Donkey22 6 130 150 170 120 160 140
Driver3 5
Donkey31 5 120 210 230 330 400
Donkey32 4 800 700 600 500
Donkey33 2 1000 800
Donkey34 1 1750
Donkey35 3 500 1000 400
)"
);
int main()
{
using weight_container = std::vector<unsigned>;
using donkey_type = std::pair<std::string, weight_container>;
using donkey_container = std::vector<donkey_type>;
std::map<std::string, donkey_container> driver_map;
std::string driver_name;
while (in >> driver_name)
{
donkey_container donkeys ;
unsigned num_donkeys;
in >> num_donkeys;
for (unsigned i = 0; i < num_donkeys; ++i)
{
donkey_type donkey;
in >> donkey.first;
unsigned num_boxes;
in >> num_boxes;
donkey.second.resize(num_boxes);
for (unsigned j = 0; j < num_boxes; ++j)
in >> donkey.second[j];
donkeys.emplace_back(std::move(donkey));
}
driver_map.emplace(driver_name, donkeys);
}
for (auto& item : driver_map)
{
auto& donkeys = item.second;
std::cout << item.first << " has " << donkeys.size() << " donkeys.\n";
for (auto& donkey : donkeys)
{
auto& name = donkey.first;
auto& weights = donkey.second;
std::cout << '\t' << name << " has " << weights.size() << " boxes weighing ";
for (auto weight : weights)
std::cout << weight << ' ';
std::cout << '\n';
}
}
}