英文:
How can I make this multiply method return a polynomial that doesn't have repeated exponents?
问题
我需要这个方法返回简化后的多项式
例如:如果结果是 3.00x^4 + 6.00x^2 + 2.00x^3 + 4.00x + x^2 + 2.00,我需要它简化为 3.00x^4 + 2.00x^3 + 7.00x^2 + 4.00x + 2.00。
英文:
I need this method to return the simplified polynomial
for example: if the result is 3.00x^4 + 6.00x^2 + 2.00x^3 + 4.00x+x^2 + 2.00 i need it to return it simplified to 3.00x^4 + 2.00x^3 + 7.00x^2 + 4.00x + 2.00
答案1
得分: 1
这可以通过使用整数数组来实现。x的系数x<sup>n</sup>放在数组的第n<sup>th</sup>位置。当你将其添加到列表中时,将会将该数字添加到已有数字上。整数数组默认情况下在每个位置上都是0。
这将为您添加多项式。
英文:
One way to do this is to use an integer array. The coefficient of x<sup>n</sup> goes in the n<sup>th</sup> place of the array. And as you add it to the list, you'll add the number to whatever is there. Integer arrays have 0 in every position by default.
This would add polynomials for you.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论