http://www.patest.cn/contests/pat-b-practise/1010
Describe:
The design function asks for the derivative of the unary polynomial. (Note: The first derivative of xn (n is an integer) is n*xn-1. )
Input format: Enter the polynomial non 0 coefficients and indices (integers with an absolute value of not more than 1000) in an exponential degradation manner. Numbers are separated by spaces.
Output format: The coefficients and indices of the derivative polynomial not 0 items are output in the same format as the input. Numbers are separated by spaces, but there are no extra spaces at the end. Note that the "0 polynomial" index and coefficient are all 0, but the expression is "0 0". Input Sample:
3 4-5 2 6 1-2 0
Output Sample:
12 3-10 1 6 0
This is simple, but to pay attention to the details, if the derivation is 0 polynomial, can not be no output, but output "0 0".
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main ()
{
int a=0, n=0;
Cin >> a >> n;
if (n!=0)
cout << a*n << ' << n-1;
else cout << "0 0";
while (Cin >> a >> N)
if (n!=0)
cout << ' << a*n << ' << n-1;
return 0;
}