1010 univariate polynomial derivation (25 minutes)

Monadic design function of the derivative of the polynomial. (Note: x n (n is an integer) the first derivative is nx n-1.)

Input format:
In a manner descending exponential input nonzero polynomial coefficient and the exponent (integer not exceeding the absolute value of both 1000). Between numbers separated by a space.

Output format:
with the same input format output derivatives of the polynomial coefficients and the index of non-zero entries. Between numbers separated by spaces, but the end can not have extra spaces. Note that the "zero polynomial" of the index and the coefficient is 0, but expressed as 0
0.

Sample input:
34-5261-20

Output Sample:
123-10160

: Algorithm
1. Before use flag is determined not to be the space 2. Analyzing the output b is not 0, the output is not 0, 0 is not output a * b b-1 3. Note no output, and finally to output 00

#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int a, b;
    bool flag = false;
    while(cin >> a >> b)
    {
        if(b != 0)
        {
            if(flag) cout << ' ';
            cout << a * b << ' ' << b - 1;
            flag = true;
        }

    }
    if(!flag) cout << "0 0";

    return 0;
}

Guess you like

Origin blog.csdn.net/qq_42549254/article/details/93397810