#include <iostream>
#include <sstream>
#include <string>
#include <vector>
template <typename parsed_type>
std::vector<parsed_type> split(const std::string& text)
{
std::istringstream iss(text);
std::vector<parsed_type> elements;
parsed_type element;
while (iss >> element)
elements.push_back(element);
return elements;
}
template <typename container_type>
void print_container(std::ostream& os, const container_type& c)
{
std::cout << '{';
for (auto & item : c)
std::cout << ' ' << item;
std::cout << " }\n";
}
int main()
{
std::string s("1 14 22 6 7");
std::string words("alpha bravo charlie delta echo foxtrot golf");
print_container(std::cout, split<int>(s));
print_container(std::cout, split<std::string>(words));
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPHZlY3Rvcj4KCnRlbXBsYXRlIDx0eXBlbmFtZSBwYXJzZWRfdHlwZT4Kc3RkOjp2ZWN0b3I8cGFyc2VkX3R5cGU+IHNwbGl0KGNvbnN0IHN0ZDo6c3RyaW5nJiB0ZXh0KQp7CiAgICBzdGQ6OmlzdHJpbmdzdHJlYW0gaXNzKHRleHQpOwogICAgc3RkOjp2ZWN0b3I8cGFyc2VkX3R5cGU+IGVsZW1lbnRzOwogICAgcGFyc2VkX3R5cGUgZWxlbWVudDsKCiAgICB3aGlsZSAoaXNzID4+IGVsZW1lbnQpCiAgICAgICAgZWxlbWVudHMucHVzaF9iYWNrKGVsZW1lbnQpOwoKICAgIHJldHVybiBlbGVtZW50czsKfQoKdGVtcGxhdGUgPHR5cGVuYW1lIGNvbnRhaW5lcl90eXBlPgp2b2lkIHByaW50X2NvbnRhaW5lcihzdGQ6Om9zdHJlYW0mIG9zLCBjb25zdCBjb250YWluZXJfdHlwZSYgYykKewogICAgc3RkOjpjb3V0IDw8ICd7JzsKICAgIGZvciAoYXV0byAmIGl0ZW0gOiBjKQogICAgICAgIHN0ZDo6Y291dCA8PCAnICcgPDwgaXRlbTsKICAgIHN0ZDo6Y291dCA8PCAiIH1cbiI7Cn0KCmludCBtYWluKCkKew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