#include <iostream>
#include <sstream>
#include <vector>
#include <utility>

std::istream& Char( std::istream& is,
    			    char ch,
					bool skipws = true )
{
	if( skipws )
		is >> std::ws;
	if( is.get() != ch )
		is.setstate( std::ios_base::failbit );
	return is;
}

int main()
{
	std::istringstream stream("2x^4-5x^3+3.5x^2+2x-5");

	using Real = double;

	std::vector<std::pair<Real, Real>> values;

	for(;;)
	{
		Real a, b;

		if( !(stream >> std::ws >> a) )
			break;

		bool succeeded_x = false;
		if( !Char(stream, 'x')
		 || (succeeded_x = true, !Char(stream, '^')) )
		{
			stream.clear();
			stream.unget();
			b = succeeded_x;
		}

		else if( !(stream >> std::ws >> b) )
			break;

		values.emplace_back(a, b);

		if( stream.peek() != '+' 
		 && stream.peek() != '-' )
			break;
	}

	for( auto const& p : values )
		std::cout << p.first << " * x^" << p.second << '\n';
}