|
发表于 2019-10-28 21:37:09
|
显示全部楼层
- from collections import Counter
- class Kao():
- def __init__(self, A, B, C):
- self.shopGoodLst = Counter(list(A.split()))
- self.buyGoodLST = Counter(list(B.split()))
- self.soldGoodLst = Counter(list(C.split()))
- self.a, self.b = self.shopBuygoods()
- def isFoul(self):
- for good in self.shopGoodLst:
- if good not in self.soldGoodLst:
- return True
- else:
- return False
- def haveGood(self):
- for good in self.buyGoodLST:
- if good not in self.shopGoodLst:
- return True
- else:
- return False
- def shopBuygoods(self):
- a, b = '', ''
- for good in self.buyGoodLST:
- if self.shopGoodLst[good]:
- if self.buyGoodLST[good] > self.shopGoodLst[good]:
- a += good + ' ' + str(self.buyGoodLST[good] - self.shopGoodLst[good]) + '\n'
- else:
- b += good
- a += good + ' ' + str(self.buyGoodLST[good] - self.shopGoodLst[good]) + '\n'
- return a, b
- def juge(self):
- s, s1 = True, True
- if self.isFoul() and self.haveGood():
- return 'Impossible'
- if self.b or self.a:
- s = False
- if self.isFoul():
- s1 = False
- return str(s) + '\n' + str(s1) + '\n' + self.a
- A = 'Z S E E S A'
- B = 'Z Z A A S E'
- C = 'A Z'
- print(Kao(A, B, C).juge())
复制代码 |
|