Title Description
One yuan n- n-degree polynomial expression as expressed available:
f(x)=a_nx^n+a_{n-1}x^{n-1}+\cdots +a_1x+a_0,a_n\ne 0f(x)=anxn+an−1xn−1+⋯+a1x+a0,an=0
Wherein, a_ix ^ i A i X i called i i-th order term, a_i A i called i coefficients of the i-th term. Gives a univariate polynomial and the number of multipliers, the required output of the polynomial specified in the following format:
-
Is a polynomial argument X X, from left to right in descending frequency order polynomial is given.
-
Contains only the polynomial coefficients is not 0 0 entries.
-
If the polynomial the n- the n-order term coefficient is positive, then the polynomial is not the beginning of a "+" sign, if the polynomial the n- the n-order term coefficient is negative, the polynomial a "-" sign at the beginning.
For not the highest order terms to the "+" or "-" sign this connection with the previous item, respectively, this coefficient is positive or negative coefficient. Followed by a positive integer that represents the absolute value of this coefficient (if a higher than 0 the zero-order term, the absolute value of the coefficient . 1 1, the output is not necessary . 1 1). If X X greater than the index . 1 1, the exponential portion immediately next to " X ^ B X B", wherein B B is X X index; if X X's index . 1 1, the next immediately the exponent part with the form " X X"; if X X index of 0 to 0, the coefficients can only output.
Polynomials, polynomial beginning, the end, without extra spaces.
Input Format
Enter the total of 2 2 lines
The first line . 1 an integer, n- n-, the number of univariate polynomial representation.
The second row has n-1 + n- + 1 integers, the first of which I I denotes the integer n-1 + I- n- - I + coefficient of the linear term, between each two integers separated by a space.
Output Format
Total output . 1 one line, the output of the polynomial by topic format.
Sample input and output
5 100 -1 1 -3 0 10
100x^5-x^4+x^3-3x^2+10
3 -50 0 0 1
-50x^3+1
Description / Tips
NOIP 2009 universal set of the first question
Data for 100%, 0 \ n-Le \ Le 100 0 ≤ n- ≤ . 1 0 0, -100 \ Le - . 1 0 0 ≤ coefficient \ 100 Le ≤ . 1 0 0
Problem solving process:
The subject is not difficult, just pay attention to some pit:
1. Several current coefficient is 0 when a nonzero coefficient note the absence of a positive number
2. When the coefficient is time 1or-1 does not require a digital output, however! ! The last digit is a 1 or -1 when the output is needed
3. coefficient than the first non-zero coefficient to pay attention to the issue in front of the
Generally these pits, finished after his own re-test a few samples, will be able to pass basic
code show as below:
. 1 #include <bits / STDC ++ H.> 2 the using namespace STD; . 3 . 4 const int MAXN = 10005 ; . 5 typedef Long Long LL; . 6 . 7 int A, n-; . 8 int NUM [MAXN]; . 9 10 // here x the output presented separately to facilitate opening below the writing . 11 void Print ( int n-) 12 is { 13 is IF (n-== 0 ) 14 return ; 15 IF (n-> . 1 ) 16 cout<<"x^"<<n; 17 else 18 cout<<"x"; 19 return; 20 } 21 22 23 int main() 24 { 25 while(cin>>n) 26 { 27 int k=n; 28 bool flag=true; 29 for(int i=0;i<=n;++i) 30 { 31 cin>>a; 32 if(a==0) 33 { 34 k--; 35 continue; 36 } 37 if(flag) 38 { 39 if(a==1) 40 print(k); 41 else if(a==-1) 42 { 43 cout<<"-"; 44 print(k); 45 } 46 else 47 { 48 cout<<a; 49 print(k); 50 } 51 flag=false; 52 } 53 else 54 { 55 if(a==1) 56 { 57 cout<<"+"; 58 if(k!=0) 59 print(k); 60 else 61 cout<<1; 62 } 63 else if(a==-1) 64 { 65 cout<<"-"; 66 if(k!=0) 67 print(k); 68 else 69 cout<<1; 70 } 71 else if(a>0) 72 { 73 cout<<"+"<<a; 74 print(k); 75 } 76 else 77 { 78 cout<<a; 79 print(k); 80 } 81 } 82 k--; 83 } 84 cout<<endl; 85 } 86 return 0; 87 }