SDNU 1207. polynomial output (water issues)

Description

One yuan n Polynomial available following expression represents:

f(x)=an*x^n+an-1*x^n-1+...+a1*x+a0 (an≠0)

 

Which, a_i · the X-^ i called i -order terms, a_i called i coefficient order terms. Gives a univariate polynomial and the number of multipliers, the required output of the polynomial specified in the following format:

1. polynomial argument is X , the number from left to right in descending order of the polynomial is given.

2. The polynomial coefficients not only contains 0 entries.

3. If the polynomial n times coefficient is positive, it does not appear at the beginning of the polynomial "+" numbers, if the polynomial n times line item

The number is negative, the polynomial order "-" number at the beginning.

4. For the highest order terms are not to "+" number or "-" number before a connection to this, this indicate the coefficient is positive or negative coefficient. Followed by a positive integer that represents the absolute value of this coefficient (if a greater than 0 order terms, the absolute value of the coefficient is 1 , then the No output 1 ). If x is greater than the index 1 , the exponential portion immediately next to the "x ^ b" , where b is the x index; if x is index 1 , the index of the next immediately following portion of the form "x " ; if x index is 0 , the coefficients can only output.

5. polynomial, polynomial beginning, free end of the extra spaces.

Input

The first line . 1 integers, n-(. 1n≤100) , the number of univariate polynomial representation.

The second row has n + 1 integers, wherein the integer represents the i n-i + coefficients (int) 1 order terms

Output

The output common- 1 line, the output of the polynomial by topic format.

Sample Input

5
100 -1 1 -3 0 10

Sample Output

100x^5-x^4+x^3-3x^2+10

Source

Thinking: This amazing title track should not only consider the latter case, you have to be considered first item is 0, 1, -1.
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
using namespace std;
#define ll long long

int n, f[100+8];

int main()
{
    scanf("%d", &n);
    int miao = n;
    for(int i = 0; i<n+1; i++)
        scanf("%d", &f[i]);
    for(int i = 0; i<n+1; i++)
    {
        if(!i && f[i]>1)printf("%dx^%d", f[i], miao--);
        else if(!i && f[i] == 0)miao--;
        else if(!i && f[i]<-1)printf("%dx^%d", f[i], miao--);
        else if(!i && f[i] == 1)printf("x^%d", miao--);
        else if(!i && f[i] == -1)printf("-x^%d", miao--);
        else if(f[i]>1 && i<n-1) printf("+%dx^%d", f[i], miao--);
        else if(f[i] == 1 && i<n-1)printf("+x^%d", miao--);
        else if(f[i] == 0 && i<n-1)miao--;
        else if(f[i]<-1 && i<n-1)printf("%dx^%d", f[i], miao--);
        else if(f[i] == -1 && i<n-1)printf("-x^%d", miao--);
        else if(f[i]>1 && i == n-1) printf("+%dx", f[i]);//
        else if(f[i] == 1 && i == n-1)printf("+x");
        else if(f[i] == 0 && i == n-1)miao--;
        else if(f[i]<-1 && i == n-1)printf("%dx", f[i]);
        else if(f[i] == -1 && i == n-1)printf("-x");//
        else if(f[i] && i == n && f[i]>0)printf("+%d\n", f[i]);
        else if(f[i] && i == n && f[i]<0)printf("%d\n", f[i]);
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/RootVount/p/10991143.html