#include <map>
#include <vector>
#include <sstream>
#include <string>
#include <algorithm>
#include <iterator>
#include <iostream>

using namespace std;

typedef std::map<std::string, std::vector<int> > StringMap;

void AddToMap(StringMap& sMap, const std::string& line)
{
	istringstream strm(line);
	string name;
	strm >> name;
	StringMap::iterator it = sMap.insert(make_pair(name, std::vector<int>())).first;
	int num;
	while (strm >> num)
		it->second.push_back(num);
}

int main()
{
	vector<std::string> data = { "Adam 2 5 1 5 3 4", "John 1 4 2 5 22 7", "Kate 7 3 4 2 1 15", "Bill 2222 2 22 11 111" };
	StringMap vectMap;

	// Add results to map
	for_each(data.begin(), data.end(), [&](const std::string& s){AddToMap(vectMap, s); });

	// Output the results
	for_each(vectMap.begin(), vectMap.end(),
		[](const StringMap::value_type& vt)
	{cout << vt.first << " "; copy(vt.second.begin(), vt.second.end(), ostream_iterator<int>(cout, " ")); cout << "\n"; });
}
