[Group] Polynomial output 09NOIP popularity

Description] [Title
one yuan nn Polynomial available following expression represents:

F (X) = anxn + AN-1xN-. 1 + ... + A1X + A0, AN ≠ = 0
F (X) = anxn + AN-1xN-. 1 + ... + A1X + A0, AN ≠ = 0
wherein, aixiaixi said ii order term is, aiai referred ii coefficient of 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 xx, polynomial given from left to right in descending order of frequency.

  2. Polynomial coefficient is not only contains 00 items.

  3. If the polynomial nn times coefficient is positive, it does not appear at the beginning of the polynomial "+" sign, if the polynomial nn times coefficient is negative, the polynomial a "-" sign at the beginning.

  4. For not the highest order terms, the "+" sign or a "-" 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 term greater than 00 times the absolute value of the coefficient is 11, you do not need output 11). If the index is greater than 11 xx, the exponential portion immediately next to "x∧bx∧b", where xx is the index bb; xx if the index is 11, immediately following the next index portion of the form "xx";

If xx index was 00, the only output coefficient can be.

  1. Polynomials, polynomial beginning, the end, without extra spaces.

[Enter]
There are two lines

The first line 11 integers, nn, the number of univariate polynomial representation.

The second row has n + + 1 1N integer, wherein the first integer represents ii n-i + 1n-i + 1-order term coefficient, between each two integers separated by a space.

[Output]
of 1 line, according to the title of the format of the output polynomial.

[Sample] input
. 5
100. 1 -1 -3 0 10
[Output] Sample
IOOX . 5-X . 4 X + 3-3x 2 + 10
[Note]
[O] Sample 2

Input:

. 3
-50 0 0. 1
Output:

-50x ^ 3 + 1
[] data range

1≤n≤1001≤n≤100, the absolute value of each sub-polynomial coefficient of not more than 100,100.

#include<bits/stdc++.h>
using namespace std;
int flag;
int main(){
	int n, x;
	cin >> n;
	for(int i=n; i>=0; i--){
		cin >> x;
		if(i == 0){
			if(x < 0)
				cout << "-";
			if(x > 0 && flag == 1)
				cout << "+";
			if(x != 0)
				cout << abs(x);
		}else{
			if(x != 0){
				if(x < 0){
					flag = 1;
					cout << "-";
					if(x != -1)
						cout << abs(x);
				}else{
					if(flag == 1)
						cout << "+";
					flag = 1;
					if(x != 1)
						cout << x;
				}
				cout << "x";
				if(i != 1)
					cout << "^" << i;
			}
		}
	}
	return 0;
}

This problem is not difficult, but there are two details should be noted,
first: the case of plus or minus factor of 1, and is easily overlooked: the first factor whether symbol, if positive, is not necessary to use the + symbol ; and if it is negative, is needed - symbols; also exclude coefficient is 0;
second: index slightly better, no negative sign, but we have a special deal with cases of ones and zeros.

Published 15 original articles · won praise 10 · views 221

Guess you like

Origin blog.csdn.net/qq_39053800/article/details/104228663