如何使这个乘法方法返回一个没有重复指数的多项式?

huangapple go评论65阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年10月17日 09:07:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/64398132.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定