#P1067. [NOIP 2009 普及组] 多项式输出
[NOIP 2009 普及组] 多项式输出
Description
A univariate polynomial of degree can be written as:
$$f(x)=a_nx^n+a_{n-1}x^{n-1}+\cdots +a_1x+a_0,a_n\ne 0$$Here, is called the -th degree term, and is its coefficient. Given the degree and coefficients of a univariate polynomial, output the polynomial in the following format:
- The indeterminate is . List the terms from left to right in descending order of degree.
- Include only terms whose coefficients are nonzero.
- If the leading (degree-) coefficient is positive, the polynomial must not start with a
+sign; if it is negative, the polynomial must start with a-sign. - For any non-leading term, connect it to the previous term with
+or-, indicating a positive or negative coefficient, respectively. Immediately follow with the absolute value of the coefficient as a positive integer (for terms of degree greater than , omit the if the coefficient’s absolute value is ). If the exponent of is greater than , write it as “”, where is the exponent; if the exponent is , write it as ; if the exponent is , output only the coefficient. - There must be no extra spaces at the beginning or the end of the polynomial.
Input Format
There are lines of input.
- The first line contains one integer , the degree of the polynomial.
- The second line contains integers. The -th integer is the coefficient of the term of degree . Integers are separated by single spaces.
Output Format
Output one line: the polynomial formatted as described above.
5
100 -1 1 -3 0 10
100x^5-x^4+x^3-3x^2+10
3
-50 0 0 1
-50x^3+1
Hint
NOIP 2009 Junior, Problem 1.
Constraints: For 100% of the testdata, , and .
: A new set of hack testdata has been added.
Translated by ChatGPT 5
京公网安备 11011102002149号