#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
typedef std::vector< int > ints_t;
void dump_ints( const ints_t& input )
{
std::copy(
input.begin(),
input.end(),
std::ostream_iterator< int >( std::cout, " " ) );
std::cout << std::endl;
}
void foo( const ints_t& first, const ints_t& second )
{
dump_ints( first );
dump_ints( second );
}
bool parse_line( std::istream& is, ints_t* output )
{
std::string line;
if ( std::getline( is, line ) )
{
std::istringstream raw_ints( line );
std::copy(
std::istream_iterator< int >( raw_ints ),
std::istream_iterator< int >(),
std::back_inserter( *output ) );
return true;
}
else
{
return false;
}
}
bool parse( std::istream& is, ints_t* first, ints_t* second )
{
const bool result = parse_line( is, first ) && parse_line( is, second );
return result;
}
void run( std::istream& is )
{
while ( is )
{
ints_t first;
ints_t second;
if ( parse( is, &first, &second ) )
{
foo( first, second );
}
}
}
int main()
{
//if you want to read input from file use ifstream and comment istringstream
// std::ifstream is( "put_here_a_path_to_input_file" );
std::istringstream is(
"3 2 1 4 5 7 6\n"
"3 1 2 5 6 7 4\n"
"7 8 11 3 5 16 12 18\n"
"8 3 11 7 16 18 12 5\n"
"255\n"
"255\n"
);
run( is );
}