Guest User

Untitled

a guest
Mar 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.70 KB | None | 0 0
  1. input_list = []
  2. while True:
  3. input_str = input()
  4. if input_str == "":
  5. break
  6. else:
  7. input_list.append(input_str)
  8. #print(input_list)
  9.  
  10. namescores = {}
  11. for line in input_list:
  12. line_split = line.split(':')
  13. name1 = line_split[0]
  14. name2 = line_split[1]
  15. namescores[name1] = {}
  16. namescores[name2] = {}
  17. namescores[name1]['3set_game_won'] = 0
  18. namescores[name1]['5set_game_won'] = 0
  19. namescores[name2]['3set_game_won'] = 0
  20. namescores[name2]['5set_game_won'] = 0
  21. namescores[name1]['set_won'] = 0
  22. namescores[name1]['set_lost'] = 0
  23. namescores[name2]['set_won'] = 0
  24. namescores[name2]['set_lost'] = 0
  25. namescores[name1]['game_won'] = 0
  26. namescores[name1]['game_lost'] = 0
  27. namescores[name2]['game_won'] = 0
  28. namescores[name2]['game_lost'] = 0
  29. #print(str(namescores))
  30.  
  31. for line in input_list:
  32. line_split = line.split(':')
  33. name1 = line_split[0]
  34. name2 = line_split[1]
  35. scores = line_split[2]
  36. score_pairs = scores.split(',')
  37. name1_3set_won = 0
  38. name1_5set_won = 0
  39. name2_3set_won = 0
  40. name2_5set_won = 0
  41.  
  42. for score_pair in score_pairs:
  43.  
  44. score_pair_split = score_pair.split('-')
  45. namescores[name1]['game_won'] = int(namescores[name1]['game_won'])+int(score_pair_split[0])
  46. namescores[name1]['game_lost'] = int(namescores[name1]['game_lost'])+int(score_pair_split[1])
  47. namescores[name2]['game_won'] = int(namescores[name2]['game_won'])+int(score_pair_split[1])
  48. namescores[name2]['game_lost'] = int(namescores[name2]['game_lost'])+int(score_pair_split[0])
  49.  
  50. if (len(score_pairs)>3 and len(score_pairs)<=5 and (int(score_pair_split[0]) >=6 or int(score_pair_split[1]) >=6)):
  51.  
  52. if int(score_pair_split[0])>int(score_pair_split[1]):
  53. namescores[name1]['set_won'] = int(namescores[name1]['set_won'])+1
  54. namescores[name2]['set_lost'] = int(namescores[name2]['set_lost'])+1
  55. name1_5set_won += 1
  56.  
  57. elif int(score_pair_split[0])<int(score_pair_split[1]):
  58. namescores[name1]['set_lost'] = int(namescores[name1]['set_lost'])+1
  59. namescores[name2]['set_won'] = int(namescores[name2]['set_won'])+1
  60. name2_5set_won += 1
  61.  
  62. elif (len(score_pairs)<=3 and (int(score_pair_split[0]) >=6 or int(score_pair_split[1]) >=6)):
  63.  
  64. if int(score_pair_split[0])>int(score_pair_split[1]):
  65. namescores[name1]['set_won'] = int(namescores[name1]['set_won'])+1
  66. namescores[name2]['set_lost'] = int(namescores[name2]['set_lost'])+1
  67. name1_3set_won += 1
  68.  
  69. elif int(score_pair_split[0])<int(score_pair_split[1]):
  70. namescores[name1]['set_lost'] = int(namescores[name1]['set_lost'])+1
  71. namescores[name2]['set_won'] = int(namescores[name2]['set_won'])+1
  72. name2_3set_won += 1
  73.  
  74. #print(name1_5set_won)
  75. #print(name2_5set_won)
  76. #print(name1_3set_won)
  77. #print(name2_3set_won)
  78. if (name1_5set_won >=(name2_5set_won + 1)):
  79. namescores[name1]['5set_game_won'] = int(namescores[name1]['5set_game_won'])+1
  80.  
  81. elif (name2_5set_won >=(name1_5set_won + 1)):
  82. namescores[name2]['5set_game_won'] = int(namescores[name2]['5set_game_won'])+1
  83.  
  84. elif (name1_3set_won >=(name2_3set_won + 1)):
  85. namescores[name1]['3set_game_won'] = int(namescores[name1]['3set_game_won'])+1
  86.  
  87. elif (name2_3set_won >=(name1_3set_won + 1)):
  88. namescores[name2]['3set_game_won'] = int(namescores[name2]['3set_game_won'])+1
  89.  
  90. #print(namescores)
  91.  
  92. final_list = [[] for name in namescores]
  93. i=0
  94. for player in namescores:
  95. final_list[i].append(player)
  96. final_list[i].append(namescores[player]['5set_game_won'])
  97. final_list[i].append(namescores[player]['3set_game_won'])
  98. final_list[i].append(namescores[player]['set_won'])
  99. final_list[i].append(namescores[player]['game_won'])
  100. final_list[i].append(namescores[player]['set_lost'])
  101. final_list[i].append(namescores[player]['game_lost'])
  102. i += 1
  103.  
  104. final_list.sort(key=lambda x: (x[1],x[2],x[3],x[4],x[6],x[5]))
  105. final_list=final_list[::-1]
  106. #print(final_list)
  107.  
  108. for i in range (len(final_list)):
  109. print(final_list[i][0], end =" ")
  110. print(final_list[i][1], end =" ")
  111. print(final_list[i][2], end =" ")
  112. print(final_list[i][3], end =" ")
  113. print(final_list[i][4], end =" ")
  114. print(final_list[i][5], end =" ")
  115. print(final_list[i][6], end ="\n")
Add Comment
Please, Sign In to add comment