腾讯马拉松之部门竞赛



部门竞赛:
赢一场得3分,平局一分,多个并列最高没有冠军
现在记录员有肯能记错了一场比赛的结果,问给出的其中一个部门有没有可能那冠军:
(1)如果不用修改就是冠军,输出-2
(2)如果一定拿不了冠军,输出-1
(3)通过修改可以拿到冠军,输入比赛的场次,如果多场,输入靠前的。
第一行表示有几组测试数据
第二行表示有几场比赛
在比赛之后是这个部门有没有可能那冠军
input:
3
2
TEG SNG 3 2
SNG TEG 2 2
TEG
1
TEG OMG 4 0
IEG
3
TEG ECC 2 2
TEG OMG 0 0
OMG ECC 1 1
ECC
输出:
-2
-1

0


def find_index_tie(match,name=''):
               if name =='':
                   for i in match:
                       aPart,bPart,aScore,bScore = i.strip('\n').split(' ')
                       if aScore == bScore:
                           return i
               else:
                   for i in match:
                       aPart,bPart,aScore,bScore = i.strip('\n').split(' ')
                       if aScore == bScore and (aPart == name or bPart == name):
                           return i

def find_index_lose(match,name,name2=''):
                
                if name2 == '':
                   for i in match:
                       aPart,bPart,aScore,bScore = i.strip('\n').split(' ')
                       if aScore > bScore and bPart == name :
                           return i
                       if aScore < bScore and aPart == name :
                           return i
                else:
                    for i in match:
                       aPart,bPart,aScore,bScore = i.strip('\n').split(' ')
                       if aScore > bScore and bPart == name and aPart == name2:
                           return i
                       if aScore < bScore and aPart == name and bPart == name2:
                           return i
def find_index(match,name,name2=''):
                if name2 =='':
                   for i in match:
                       aPart,bPart,aScore,bScore = i.strip('\n').split(' ')
                       if aScore > bScore and bPart == name:
                           return i
                       if aScore < bScore and aPart == name:
                           return i
                       if aScore == bScore:
                           return i
                else:
                    for i in match:
                       aPart,bPart,aScore,bScore = i.strip('\n').split(' ')
                       if aScore > bScore and bPart == name and aPart == name2:
                           return i
                       if aScore < bScore and aPart == name and bPart == name2:
                           return i
                       if aScore == bScore and aPart == name2:
                           return i
                    
               
def anay(name,match,dic,match_list):
    lose_match_count = tie_match_count = 0
    for i in match:
                   if i.find(name) != -1:
                       match_list.append(i)
                   aPart,bPart,aScore,bScore = i.strip('\n').split(' ')
                   if not dic.has_key(aPart):
                       dic[aPart] = 0
                   if not dic.has_key(bPart):
                       dic[bPart] = 0                    
                   a = int(aScore)
                   b = int(bScore)
                   if a == b:
                       if name ==aPart or name == bPart:
                           tie_match_count +=1
                       dic[aPart] +=1
                       dic[bPart] +=1
                   if a > b:
                       if name == bPart:
                           lose_match_count +=1
                       dic[aPart] +=3
                   if b > a:
                       if name == aPart:
                           lose_match_count +=1
                       dic[bPart] +=3
    return lose_match_count,tie_match_count
                       
def evalue(name,match):
               dic = {}
               result = []
               match_list=[]
               
               lose_match_count,tie_match_count = anay(name,match,dic,match_list)
               
               if not dic.has_key(name):
                   return -1
               score = dic[name]
               for i in sorted(dic.items(),key=lambda e:e[1],reverse=True):
                   result.append(i)
               
               maxScore = result[0][1]
               secondScore = result[1][1]
               first_second = maxScore - secondScore
               dif = maxScore - score
               
                #1=score>2
               if dif ==0 and first_second:
                   return -2
               #1=score=2
               if dif ==0 and not first_second:
                   # could gain score
                   if lose_match_count ==0 and tie_match_count == 0:
                        -1
                   else:
                       match_string = find_index(match_list,name)
                       return match.index(match_string)
               if dif == 1:
                   if lose_match_count ==0 and tie_match_count == 0:
                       return -1
                   if lose_match_count:
                       match_string = find_index_lose(match_list,name)
                       return match.index(match_string)
                   #you liang ge zui da de
                   if tie_match_count :
                       match_string = find_index_tie(match_list)
                       return match.index(match_string)
               if dif == 2:
                   if lose_match_count ==0 and tie_match_count == 0:
                       return -1
                   if lose_match_count:
                       match_string = find_index_lose(match_list,name)
                       return match.index(match_string)
                   #you liang ge zui da de
                   if tie_match_count and first_second:
                       #you ping ju pan duan shi fou shi he di yi d ping ju
                       mathc_string = find_index_tie(match_list,result[0][0])
                       return match.index(match_string)
                   return -1                    
                    
               # you liangge zui da de 
               if dif == 3:
                   if lose_match_count == 0 or not first_second:
                       return -1
                   else:
                       mathc_string = find_index(match_list,name,result[0][0])
                       return match.index(match_string)
                      

sysFile = open("C:/match.txt",'r')
record = sysFile.readlines()
groupNum = int(record[0])
record = record[1:]

for i in range(groupNum):
    matchNum = int(record[0])
    matchList = record[1:matchNum+1]
    matchName = record[matchNum+1].strip('\n')
#    print matchNum
#    print matchName
#    for i in matchList:
#        print i
    result = evalue(matchName,matchList)
    print result
#    print "===================="
    record = record[matchNum+2:]
  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值