Luogu P1067 polynomial output, Luogu p1067 Polynomial
Description
The following expression can be used to represent the n-degree polynomial of a dollar:
Among them, aixi is called the I term, and ai is called the coefficient of the I term. The number of times and coefficients of a polynomial are given. output the polynomial according to the following format:
1. The self-variable in polynomial is x, and the polynomial is given in descending order of numbers from left to right.
2. polynomials only contain items whose coefficients are not 0.
3. If the n-entry coefficient of the polynomial is positive, the "+" sign does not appear at the beginning of the polynomial. If the n-entry coefficient of the polynomial is
If the number is negative, the polynomial starts.
4. For items that are not the highest, use "+" or "-" to connect this item with the previous one, indicating this item respectively.
The coefficient is positive or the coefficient is negative. Followed by a positive integer, indicating the absolute value of this coefficient (if an item is greater than 0,
If the absolute value of the coefficient is 1, 1 is not required ). If the index of x is greater than 1, the shape of the index that follows
Formula: "x ^ B", where B is the index of x. If the index of x is 1, the next index is in the form of "x ";
If the index of x is 0, you only need to output the coefficient.
5. In a polynomial, the start and end of the polynomial do not contain any extra space.
Input/Output Format
Input Format:
There are 2 rows in the input.
The first line is an integer (n), indicating the number of times of the polynomial.
The second row has n + 1 integers, where the I-th integer represents the coefficient of the n-I + 1 entry, and each two integers are empty.
Cells.
Output Format:
The output contains one row, and the polynomial is output according to the format described in the topic.
Input and Output sample input sample #1: Copy
5 100 -1 1 -3 0 10
Output example #1: Copy
100x^5-x^4+x^3-3x^2+10
Input example #2: Copy
3 -50 0 0 1
Output sample #2: Copy
-50x^3+1
Description
No. 1 in NOIP 2009 popularization Group
For 100% data, 0 <= n <= 100,-100 <= coefficient <= 100
I don't want to see this question any more.
Difficult or difficult. Pay attention to many special judgments
It is recommended that you do not view my code, Especially ghost animals.
#include<cstdio>#include<algorithm>#include<cstdlib>const int MAXN=3*1e6+10;using namespace std;inline int read(){ char c=getchar();int x=0,f=1; while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();} return x*f;}int main(){ int N=read(),flag=1; for(int i=N;i>=0;i--) { int x=read(); if(x==0) continue; if(flag==1&&x>0) flag=0; else x>0?printf("+"):printf("-"); flag=0; if(x!=1&&x!=-1) printf("%d",abs(x)); if((x==1||x==-1)&&(i==0)) printf("%d",abs(x)); if(i!=1&&i!=0) printf("x^%d",i); if(i==1) printf("x"); } return 0;}