/* Author: Yan Huang (01.16.07) 
   to show how to read a polynomial in the format of
   +2x^7+12.3x^3+23x^2+1x^0*/

#include <iostream>
#include <list>
#include <string>
using namespace std;


class Component{
      char sign; 
      float coefficient;
      float exponent;
   public:
      Component(char s, float c, float e){sign = s; coefficient = c; exponent = e;};
      void printComponent();
/*add other methods here*/ 
};

void Component::printComponent(){
	cout << sign << coefficient << "x^" << exponent;
};

int readComponent(char &s, float &c, float &e){
   char l;

   l = cin.get();
   if ( l == '+' || l == '-'){
	s = l;
        cin >> c;
	cin.get();cin.get();
        cin >> e;
   }
   else if (l == '\n') return 0;
   return 1;
}

main()
{
   list<Component> L1;
   float c,e;
   char s;
	


   while (readComponent(s,c,e)){
	Component component(s,c,e);
   	L1.push_back(component);              // Insert a new element at the end
   }


   list<Component>::iterator i;

   for(i=L1.begin(); i != L1.end(); ++i) 
	(*i).printComponent();
   cout << endl;

   return 0;
}


