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 yookwi 1 / 3723 2 / 3723 2 / 3714 1 / 2611 1 / 2604 3 / 2604 1 / 1569 7 / 3803
  9. 2 hms0510 1 / 5544 3 / 5560 4 / 7085 3 / 8439 0 / -- 0 / -- 0 / -- 4 / 8579
  10. 3 glnthd02 1 / 2514 1 / 2518 3 / -- 0 / -- 1 / 2579 0 / -- 0 / -- 3 / 2579
  11. 4 kdh9158kdh 4 / 1005 1 / 5831 6 / 8686 0 / -- 0 / -- 0 / -- 0 / -- 3 / 8846
  12. 5 rlawoaks 1 / 704 2 / 711 1 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 731
  13. 6 jjhlemon 1 / 822 1 / 849 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 849
  14. 7 h1234000 1 / 2463 1 / 2486 2 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 2486
  15. 8 mhw0502 2 / 3759 1 / 3769 4 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 3789
  16. 9 likescape 0 / -- 0 / -- 0 / -- 0 / -- 3 / -- 0 / -- 0 / -- 0 / 0
  17. """
  18. info = info.splitlines(keepends = True)
  19. if info[0] == "\n": info.pop(0)
  20.  
  21. # 랜덤 시드
  22. mod = 4294967296 # 2^32
  23. seed_string = "Hello, AlKon!"
  24. random_seed = int.from_bytes(hashlib.sha256(seed_string.encode()).digest(), 'big') % mod
  25. np.random.seed(random_seed)
  26.  
  27. participants = {}
  28. for participant in info:
  29. participant = participant.split('\t')
  30. user = participant[1]
  31. corrects = int(participant[-1].split(' / ')[0])
  32. if user in participants:
  33. participants[user] = max(participants[user], corrects + 3)
  34. else: participants[user] = corrects + 3
  35.  
  36. # 추첨 명단 제외 리스트
  37. except_list = ['aerae']
  38. for except_user in except_list:
  39. try:
  40. participants.pop(except_user)
  41. except:
  42. pass
  43.  
  44. # 추첨 확률 설정
  45. winner_percent = [0] * len(participants)
  46. correct_problems_sum = sum(participants.values())
  47.  
  48. for i, corrects in enumerate(list(participants.values())):
  49. winner_percent[i] = corrects / correct_problems_sum
  50.  
  51. print(f'랜덤 시드: {seed_string}')
  52. print(f'{len(participants)}명 {list(participants.keys())}')
  53. # print(f'맞은 문제 개수: {list(participants.values())}')
  54. # print(f'확률: {winner_percent}')
  55.  
  56. # 당첨자
  57. winner = np.random.choice(list(participants.keys()), winner_num, replace = False, p = winner_percent) \
  58. if winner_num < len(participants) else list(participants.keys())
  59. winner.sort()
  60. print(f'당첨자: {winner}')# your code goes here
Success #stdin #stdout 1.06s 41372KB
stdin
Standard input is empty
stdout
랜덤 시드: Hello, AlKon!
9명 [' yookwi', ' hms0510', ' glnthd02', ' kdh9158kdh', ' rlawoaks', ' jjhlemon', ' h1234000', ' mhw0502', ' likescape']
당첨자: [' hms0510' ' jjhlemon' ' rlawoaks']