The design function is to find the derivative of the polynomial of one element.
input format: input polynomial non-0 coefficients and exponents in exponential degradation (absolute values are integers not exceeding 1000). The numbers are separated by a space.
output format: outputs the coefficients and exponents of the derivative polynomial not 0 in the same format as the input. The numbers are separated by a space, but cannot have extra spaces at the end. Note that the exponent and coefficients for the "0 polynomial" are 0, but are expressed as "0 0".
Input Sample:
3 4-5 2 6 1-2 0
Sample output:
12 3-10 1) 6 0
Idea: Enter two numbers at a time, b press CTRL + Z to end the input. Save in S[b], and make s[b] = A;
Note: The remaining coefficients are 0 o'clock and output" 0 0 "
except 0 square coefficients
#include <iostream>using namespace Std;int main () { int s[1001] = {0}, a, B, Max; int flag = 0; while (Cin >> a >> b) { if (flag = = 0) { Max = b; flag = 1; } S[B] = A; } Flag = 0; int flag1 = 0; for (int i = Max; I >= 0; i--) { if (s[i]! = 0 && i > 0 && flag = = 0) { cout <& Lt S[i]*i << "" << i-1; flag = 1; Flag1 = 1; } else if (s[i]! = 0 && i > 0 && flag = = 1) { Flag1 = 1; cout << "<<s[i]*i <<" "<< i-1; } } if (Flag1 = = 0) cout << "0 0"; return 0;}
PAT 1010. Derivation of one-dimensional polynomial (25)