ZJU PAT 1012 The Best Rank

给出学生3门课的成绩,求每名学生在3门课以及平均分中所能取得的最高排名。

这是一道极水的题目,却提交了n次才过,一开始以为是平均分求法的问题,后来才发现关键在于并列排名的处理上:应该是1 2 3 3 5,而不是1 2 3 3 4

 1 from operator import itemgetter
 2 n, m = raw_input().split()
 3 dictC = {}
 4 dictM = {}
 5 dictE = {}
 6 dictA = {}
 7 for i in range(int(n)):
 8     list = raw_input().split()
 9     dictC[list[0]] = int(list[1])
10     dictM[list[0]] = int(list[2])
11     dictE[list[0]] = int(list[3])
12     dictA[list[0]] = (int(list[1]) + int(list[2]) + int(list[3]))/3
13 listC = sorted(dictC.values(), reverse=True)
14 listM = sorted(dictM.values(), reverse=True)
15 listE = sorted(dictE.values(), reverse=True)
16 listA = sorted(dictA.values(), reverse=True)
17 for j in range(int(m)):
18     stu = raw_input()
19     if stu in dictC.keys():
20         position = {}
21         position['C'] = listC.index(dictC[stu])
22         position['M'] = listM.index(dictM[stu])
23         position['E'] = listE.index(dictE[stu])
24         position['A'] = listA.index(dictA[stu])
25         a = min(position.values())
26         print a+1,
27         if position['A'] == a:
28             print 'A'
29         elif position['C'] == a:
30             print 'C'
31         elif position['M'] == a:
32             print 'M'
33         else:
34             print 'E'
35     else:
36         print "N/A"

 

posted @ 2013-01-23 14:43  S.Zhang  阅读(1744)  评论(1编辑  收藏  举报