A+B for Polynomials
Input Specification:
This time, you are supposed to find A+B where A and B are two polynomials.
Output Specification:
Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial:K N1 aN1 N2 aN2 … aNK
where K is the number of nonzero terms in the polynomial, Ni 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.
Sample Input:
1 | 2 1 2.4 0 3.2 |
Sample Output:
1 | 3 2 1.5 1 2.9 0 3.2 |
Analysis
其K为多项式中非零项的个数,共输入两行。于是分别定义指数为正的数组polynomial,以及指数为负数的数组min。分别输入通过数组下标表示指数,相同则在输入的时候进行相加,不相同则添加到对应下标下。注意输出格式o( ̄▽ ̄)o
Code
C
1 |
|
Result
If you like this blog or find it useful for you, you are welcome to comment on it. You are also welcome to share this blog, so that more people can participate in it. If the images used in the blog infringe your copyright, please contact the author to delete them. Thank you !