PTA甲级——1009
1009 Product of Polynomials
This time, you are supposed to find A×B where A and B are two polynomials.
Input Specification:
Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial:
$$
\begin{flalign}
K\ N_1\ a_{N_1}\ N_2\ a_{N_2}\ N_2\ a_{N_2}\ … N_k\ a_{N_k}\\
\end{flalign}
$$
where K is the number of nonzero terms in the polynomial, N i and a N i (i=1,2,⋯,K) are the exponents and coefficients, respectively. It is given that 1≤K≤10, 0≤N K<⋯<N2<N1≤1000.
Output Specification:
For each test case you should output the product of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate up to 1 decimal place.
Sample Input:
1 |
|
Sample Output:
1 |
|
思路
题目和1002的思路非常接近,没看过的可以先看看1002.
大致题意:和1002的区别就是这道题目是给两个多项式然后相乘,1002是相加。
思路:其实就是一个模拟相乘的过程,可以将第一个多项式的每一项和第二个多项式的每一项都相乘一下然后就ok了。
代码
1 |
|