﻿ Fuzhou University OnlineJudge ﻿
Problem 1606 Format the expression

## Problem Description

Oaiei is a good boy who loves math very much, he would like to simplify some mathematical expression, can you help him? For the sake of simplicity, the form of expression he wanted to simplify is shown as follows:

1. General characters
• num: an integer (0 <= num <= 1000)
• X: unknown variable
• X^num: num power of X
• numX: the coefficient of the unknown variable X is num
2. Connector character
• +: General characters connected with the character which expresses the addition
• -: General characters connected with the character which expresses the subtraction
Given the expression, your task is conversion the expression to the simplest form.

## Input

Given the expression S, the length of S is less than 200, there is no space in the given string.

## Output

Output the simplest expression S’, you should output S’ accordance to the X with descending order of power. Note that X^1 need only output X, 1X need only output X.

## Sample Input

4X^5+8X^5+4X+3X^0+8 -4X^5-3X^5

## Sample Output

12X^5+4X+11 -7X^5

## Source

FOJ月赛-2008年5月

Submit  Back  Status  Discuss
﻿