這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)Python中怎么實(shí)現(xiàn)一元多項(xiàng)式的相加相乘運(yùn)算,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
成都創(chuàng)新互聯(lián)公司專注于愛(ài)民企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站建設(shè),成都商城網(wǎng)站開(kāi)發(fā)。愛(ài)民網(wǎng)站建設(shè)公司,為愛(ài)民等地區(qū)提供建站服務(wù)。全流程按需策劃,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,成都創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)
class ListNode:
def init(self, x, y):
self.c = x
self.e = y
self.next = None
class Solution:
def ReadandLink(self,N):
self.N=N a0=ListNode(0,0) a0.next=None c0=a0 for i in range(1,N+1): c=int(input("系數(shù):")) e=int(input("指數(shù):")) b0=ListNode(c,e) a0.next=b0 a0=b0 return c0
def add(head1,head2):
node1=head1.next node2=head2.next add0=ListNode(0,0) add0.next=None head3=add0 while(node1!=None and node2!=None): if(node1.e==node2.e ): add1=ListNode(node1.c+node2.c,node1.e) add0.next=add1 add0=add1 node1=node1.next node2=node2.next elif(node1.e>node2.e ): add1=ListNode(node1.c,node1.e) add0.next=add1 add0=add1 if(node1.next!=None): node1=node1.next else: node1=node1.next break elif(node1.e<node2.e): add1=ListNode(node2.c,node2.e) add0.next=add1 add0=add1 if(node2.next!=None): node2=node2.next else: node2=node2.next break while(node1==None and node2!=None): add1=ListNode(node2.c,node2.e) add0.next=add1 add0=add1 if(node2.next!=None): node2=node2.next else: break while(node2==None and node1!=None): add1=ListNode(node1.c,node1.e) add0.next=add1 add0=add1 if(node1.next!=None): node1=node1.next else: break return head3
def multi(head1,head2):
multi_node1=head1.next
multi_node2=head2.next
add_two=ListNode(0,0)
add_two.next=None
while( multi_node1!=None):
multi0=ListNode(0,0)
multi0.next=None
head4=multi0
while(multi_node2!=None): multi_c=multi_node1.c*multi_node2.c multi_e=multi_node1.e+multi_node2.e multi1=ListNode(multi_c,multi_e) multi0.next=multi1 multi0 = multi1 multi_node2=multi_node2.next multi_node2=head2.next multi_node1=multi_node1.next add_two=add(add_two,head4)
return add_two
t1=Solution()
t2=Solution()
N1=int(input("多項(xiàng)式的項(xiàng)數(shù):"))
head1=t1.ReadandLink(N1)
N2=int(input("多項(xiàng)式的項(xiàng)數(shù):"))
head2=t2.ReadandLink(N2)
head3=add(head1,head2)
first=head3.next
print("加和結(jié)果")
while(first!=None):
print("系數(shù)=%d 指數(shù)等于%d"%(first.c,first.e))
first=first.next
head4=multi(head1,head2)
second=head4.next
print("乘積結(jié)果")
while(second!=None):
print("系數(shù)=%d 指數(shù)等于%d"%(second.c,second.e)) second=second.next
上述就是小編為大家分享的Python中怎么實(shí)現(xiàn)一元多項(xiàng)式的相加相乘運(yùn)算了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
當(dāng)前名稱:Python中怎么實(shí)現(xiàn)一元多項(xiàng)式的相加相乘運(yùn)算
路徑分享:http://vcdvsql.cn/article44/jhgche.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、動(dòng)態(tài)網(wǎng)站、用戶體驗(yàn)、外貿(mào)網(wǎng)站建設(shè)、、營(yíng)銷型網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)