P1067 polynomial output NOIP09 JuniorT1

Source: Internet
Author: User

Topic description

A unary n polynomial can be represented by an expression such as the following:

Wherein, the Aixi is called the i-th term, and the AI is called the coefficient of the i-th term. Given the number and coefficients of each item of one-element polynomial, please output the polynomial according to the format specified below:

In polynomials, the argument is x, and the polynomial is given in descending order of number from left to right.

A polynomial contains only items with a factor of not 0.

If the polynomial n-term coefficients are positive, then the polynomial does not appear at the beginning of the "+" number, if the polynomial N-term system

Number is negative, the polynomial begins with a "-" sign. For items that are not the highest, connect this item with the previous item with a "+" or "-" sign, respectively

The coefficient is positive or the coefficient is negative. Immediately followed by a positive integer that represents the absolute value of this factor (if an item above 0 times,

The absolute value of the coefficient 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 X is 1, then the next exponential part is "X";

If the index of x is 0, then only the output coefficient is required. In a polynomial, the beginning and end of a polynomial does not contain extra spaces.

Input and output formats

Input format:
Enter a total of 2 lines

The first line, 1 integers, n, represents the number of unary polynomials.

The second line has a n+1 integer in which the first integer represents the coefficients of the n-i+1, with an empty space between each of the two integers

Grid separated.

Output format:
Output a total of 1 lines, according to the format of the problem output polynomial.

Input and Output sample

Enter Sample #:
Poly1.in
5
100-1 1-3 0 10

Poly2.in
3
-50 0 0 1
Output Sample #:
Poly1.out
100x^5-x^4+x^3-3x^2+10

Poly2.out
-50x^3+1
Description
For 100% data, the 0<=n<=100,-100<= coefficient <=100

//draw a axis ... -1 ...
0...1. #include <iostream> #include <cstdio> using namespace std; 
int n,xs;   int main () {cin>>n; Index cin>>xs;
    Coefficient/* processing coefficient/if (xs>1 | | xs<-1) cout<<xs;
    else if (xs==-1) cout<< "-";
        /* Processing Index */if (xs!=0) {if (n==1) cout<< "X"; 
    else if (n!=0) cout<< "x^" <<n;
        for (int i=n-1;i>=1;i--) {cin>>xs;         /* Processing coefficient */if (xs==0) continue;       The coefficient is 0 if (xs>0) cout<< "+";     Coefficient >0 if (xs==-1) cout<< "-";
        The coefficient is-1 else if (xs!=1) cout<<xs;//is a number other than 0,-1,1/* Processing index/if (i==1) cout<< "X";
    else if (i!=0) cout<< "x^" <<i;
    } cin>>xs;
    /* Only processing coefficient * */if (xs>0) cout<< "+";
if (xs!=0) cout<<xs; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.