source of the topic
www.luogu.org
Original Address
http://www.luogu.org/problem/show?pid=1067#
Title DescriptionThe unary n-th polynomial can be expressed as follows:
Where Aixi is called i-th term, the AI is called the coefficient of i-th term. Given the number of times and coefficients for a unary polynomial, output the polynomial in the format required as follows:
1.
In the polynomial, the independent variable is x, and the polynomial is given in descending order of the number of times from left to right.
2.
Only items with a factor not 0 are included in the polynomial.
3.
If the polynomial n coefficient is positive, the "+" sign does not appear at the beginning of the polynomial, if the polynomial n-th
Number is negative, the polynomial begins with the "-" sign.
4.
For items that are not the highest, the "+" or "-" numbers are connected to the previous item, respectively.
The coefficients are positive or the coefficients are negative. followed by a positive integer that represents the absolute value of this coefficient (if an item is more than 0 times
The absolute value of the coefficients is 1, no output 1 is required. If the exponent of x is greater than 1, then the shape of the exponential part that follows
The formula is "X^b", where B is the exponent of X, and if the exponent of X is 1, then the exponential part that follows is "X";
If the exponent of x is 0, only the output coefficients are required.
5.
In a polynomial, the beginning and end of a polynomial does not contain extra spaces.
input/output formatInput format:
Enter a total of 2 lines
The first row of 1 integers, n, represents the number of times a unary polynomial is.
The second line has n+1 integers, where the i integer represents the coefficients of the n-i+1, with an empty space between every two integers
separated by a grid. Output format:
Output a total of 1 lines, according to the format of the topic output polynomial. input and Output sample input Example # #:
Poly1.in
5
100-1 1-3 0
poly2.in
3
-50 0 0 1
Sample # # of output:
Poly1.out
100x^5-x^4+x^3-3x^2+10
poly2.out
-50x^3+1
DescriptionNOIP 2009 Universal group first question
Exercises
This problem is actually not difficult, is a pure simulation plus a few if statements, pay attention to 0,1 and other details.
Code: VAR n,i:longint; A:ARRAY[1..1000] of Longint; Begin READLN (n); Inc (N); For I:=1 to n do read (A[i]); For I:=1 to N does if a[i]<>0 then BEGIN if a[i]<0 then write ('-') else if I<>1 then write (' + '); A[i]:=abs (A[i]); if (ABS (a[i)) <>1) or (i=n) then write (A[i]); If I<>n then write (' X '); if (i<>n) and (n-i<>1) then write (' ^ ', n-i); End End.