• 一、题意理解
• 二、求解思路

一、题意理解

• 先在一行中给出该树的结点树，随后N行

• 第i行对应编号第i个结点，给出该结点中存储的字母、其左孩子结点的编号、右孩子结点的编号
• 如果孩子结点为空，则在相应位置给出“-”

二、求解思路

```          ```
# python语言实现

L1 = list(map(int, input().split()))
L2 = list(map(int, input().split()))

# 节点
class Node:
def __init__(self, coef, exp):
self.coef = coef
self.exp = exp
self.next = None

# 单链表
class List:
def __init__(self, node=None):

# 为了访问私有类

def travel(self):
if cur1.next != None:
cur1 = cur1.next
else:
print(cur2.coef, cur2.exp, end="")
return
while cur1.next != None:
print(cur2.coef, cur2.exp, end=" ")
cur1 = cur1.next
cur2 = cur2.next

print(cur2.coef, cur2.exp, end=" ")
cur2 = cur2.next
print(cur2.coef, cur2.exp, end="")

# add item in the tail
def append(self, coef, exp):
node = Node(coef, exp)
else:
while cur.next != None:
cur = cur.next
cur.next = node

l3 = List()
while (p1 is not None) & (p2 is not None):
if (p1.exp > p2.exp):
l3.append(p1.coef, p1.exp)
p1 = p1.next
elif (p1.exp < p2.exp):
l3.append(p2.coef, p2.exp)
p2 = p2.next
else:
if (p1.coef + p2.coef == 0):
p1 = p1.next
p2 = p2.next
else:
l3.append(p2.coef + p1.coef, p1.exp)
p2 = p2.next
p1 = p1.next
while p1 is not None:
l3.append(p1.coef, p1.exp)
p1 = p1.next
while p2 is not None:
l3.append(p2.coef, p2.exp)
p2 = p2.next
l3.append(0, 0)
return l3

def mull(l1, l2):
l3 = List()
l4 = List()
if (p1 is not None) & (p2 is not None):
while p1 is not None:
while p2 is not None:
l4.append(p1.coef * p2.coef, p1.exp + p2.exp)
p2 = p2.next
l4 = List()
p1 = p1.next
else:
l3.append(0, 0)
return l3

def L2l(L):
l = List()
L.pop(0)
for i in range(0, len(L), 2):
l.append(L[i], L[i + 1])
return l

l1 = L2l(L1)
l2 = L2l(L2)
l3 = List()
l3 = mull(l1, l2)
l3.travel()
print("")
l3 = List()
l3.travel()

```
```

QQ号联系： 360901061

【本文对您有帮助就好】