Rokua P1067 Polynomial output simulation

Source: Internet
Author: User
Tags first row

https://www.luogu.org/problemnew/show/1067


Topic:

Title Description

The 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 argument 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, connect to the previous item with a "+" or "-", respectively, to indicate this

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 polynomial, the beginning and end of a polynomial does not contain extra spaces. Input output format input 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.

Code:

#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int A;
    int n;
    cin>>n;
    for (int i=n;i>=0;i--) {
		cin>>a;
		if (a) {
			if (a>0&&i!=n) cout<< "+";	Positive Sign Output
			if (a>1| | a<-1| | i==0) cout<<a;
			if (a==-1&&i) cout<< '-';
			if (i>1) cout<< "x^" <<i;
			if (i==1) cout<< "x";
		}
    }
    cout<<endl;
    return 0;
}


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.