ZJU PAT 1009 Product of Polynomials
从这贴开始不贴题目了,贴个链接吧 http://pat.zju.edu.cn/contests/pat-practise/1009
1002题的改进版,加法变乘法
1 def ParseList(list): 2 dict = {} 3 for j in range(int(list[0])): 4 a = int(list[j*2+1]) 5 b = float(list[j*2+2]) 6 dict[a] = b 7 return dict 8 dict1 = ParseList(raw_input().split()) 9 dict2 = ParseList(raw_input().split()) 10 dict = {} 11 for k, v in dict1.iteritems(): 12 for x, y in dict2.iteritems(): 13 a = k + x 14 b = v * y 15 if a in dict.keys(): 16 dict[a] = dict[a]+b 17 if abs(dict[a]) < 0.00001: 18 del(dict[a]) 19 else: 20 dict[a] = b 21 print len(dict), 22 items = dict.keys() 23 items.sort() 24 for item in reversed(items): 25 print "%d %.1f" % (item, dict[item]),