fork download
  1. import numpy as np
  2. import hashlib
  3.  
  4. # 추첨 인원수
  5. winner_num = 3
  6. # BOJ 연습란을 텍스트로 긁어오면 됩니다 (랭킹, 아이디, A, B, C, ... 맨 윗줄 제외하고)
  7. info = """
  8. 1 glnthd02 1 / 322 1 / 325 1 / 341 2 / 397 1 / 381 1 / 364 3 / 833 7 / 893
  9. 2 import1234 1 / 6875 1 / 5838 2 / 3570 1 / 2742 1 / 1831 1 / 321 3 / 144 7 / 6935
  10. 3 h1234000 3 / 861 1 / 868 1 / 1116 1 / 1157 2 / 1275 7 / 1349 0 / -- 6 / 1529
  11. 4 csm8717 3 / 1170 3 / 1190 1 / 1204 1 / 8559 31 / -- 0 / -- 0 / -- 4 / 8639
  12. 5 hms0510 1 / 925 2 / 933 1 / 954 0 / -- 0 / -- 0 / -- 0 / -- 3 / 974
  13. 6 jjhlemon 1 / 958 5 / 5761 1 / 5818 0 / -- 0 / -- 0 / -- 0 / -- 3 / 5898
  14. 7 kdh9158kdh 1 / 2309 2 / 2341 2 / 5971 0 / -- 0 / -- 0 / -- 0 / -- 3 / 6011
  15. 8 tim0929 1 / 3 1 / 41 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 41
  16. 9 rlawoaks 1 / 4134 2 / 4138 1 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 4158
  17. 10 dlwjdals2002 3 / 4309 0 / -- 1 / 4348 0 / -- 0 / -- 0 / -- 0 / -- 2 / 4388
  18. 11 bwgreen 1 / 4982 1 / 4985 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 4985
  19. 12 fish13031e 1 / 219 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 1 / 219
  20. 13 siubeom 2 / 1105 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 1 / 1125
  21. 14 motsuni04 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 1357 0 / -- 1 / 1377
  22. 15 aerae 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 1 / 3307 0 / -- 1 / 3307
  23. """
  24. info = info.splitlines(keepends = True)
  25. if info[0] == "\n": info.pop(0)
  26.  
  27. # 랜덤 시드
  28. mod = 4294967296 # 2^32
  29. seed_string = "Hello, AlKon!"
  30. random_seed = int.from_bytes(hashlib.sha256(seed_string.encode()).digest(), 'big') % mod
  31. np.random.seed(random_seed)
  32.  
  33. participants = {}
  34. for participant in info:
  35. participant = participant.split('\t')
  36. user = participant[1]
  37. corrects = int(participant[-1].split(' / ')[0])
  38. if user in participants:
  39. participants[user] = max(participants[user], corrects + 3)
  40. else: participants[user] = corrects + 3
  41.  
  42. # 추첨 명단 제외 리스트
  43. except_list = ['aerae']
  44. for except_user in except_list:
  45. try:
  46. participants.pop(except_user)
  47. except:
  48. pass
  49.  
  50. # 추첨 확률 설정
  51. winner_percent = [0] * len(participants)
  52. correct_problems_sum = sum(participants.values())
  53.  
  54. for i, corrects in enumerate(list(participants.values())):
  55. winner_percent[i] = corrects / correct_problems_sum
  56.  
  57. print(f'랜덤 시드: {seed_string}')
  58. print(f'{len(participants)}명 {list(participants.keys())}')
  59. print(f'맞은 문제 개수: {list(participants.values())}')
  60. print(f'확률: {winner_percent}')
  61.  
  62. # 당첨자
  63. winner = np.random.choice(list(participants.keys()), winner_num, replace = False, p = winner_percent) \
  64. if winner_num < len(participants) else list(participants.keys())
  65. winner.sort()
  66. print(f'당첨자: {winner}')# your code goes here
Success #stdin #stdout 0.8s 41372KB
stdin
Standard input is empty
stdout
랜덤 시드: Hello, AlKon!
15명 [' glnthd02', ' import1234', ' h1234000', ' csm8717', ' hms0510', ' jjhlemon', ' kdh9158kdh', ' tim0929', ' rlawoaks', ' dlwjdals2002', ' bwgreen', ' fish13031e', ' siubeom', ' motsuni04', ' aerae']
맞은 문제 개수: [10, 10, 9, 7, 6, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4]
확률: [0.1111111111111111, 0.1111111111111111, 0.1, 0.07777777777777778, 0.06666666666666667, 0.06666666666666667, 0.06666666666666667, 0.05555555555555555, 0.05555555555555555, 0.05555555555555555, 0.05555555555555555, 0.044444444444444446, 0.044444444444444446, 0.044444444444444446, 0.044444444444444446]
당첨자: [' h1234000' ' kdh9158kdh' ' tim0929']