1009 Product of Polynomials (25 分)
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:
K N1 a**N1 N2 a**N2 … N**K aNK
where K is the number of nonzero terms in the polynomial, N**i and aNi (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 | 2 1 2.4 0 3.2 |
Sample Output:
1 | 3 3 3.6 2 6.0 1 1.6 |
作者: CHEN, Yue
单位: 浙江大学
时间限制: 400 ms
内存限制: 64 MB
代码长度限制: 16 KB
题目大意
输入指数和系数代表两个多项式,要求输出相乘之后的结果
分析
使用结构体po代表一项,利用vector存储po代表一个多项式。先缓存第一个,然后在线处理第二个,将每一项相乘的结果存入res,合并指数相同的项即可。注意系数为0的项不输出。
代码
1 |
|