fork(1) download
  1. import numpy as np
  2. import hashlib
  3.  
  4. # 추첨 인원수
  5. winner_num = 5
  6. # BOJ 연습란을 텍스트로 긁어오면 됩니다 (랭킹, 아이디, A, B, C, ... 맨 윗줄 제외하고)
  7. info = """
  8. 1 glnthd02 1 / 4400 1 / 4411 1 / 4401 1 / 4434 2 / 4512 4 / 4629 0 / -- 6 / 26787
  9. 2 bwgreen 1 / 8572 1 / 8579 1 / 8579 1 / 8599 3 / 8679 1 / 8650 0 / -- 6 / 51658
  10. 3 psh030122 3 / 2831 0 / -- 2 / 5541 0 / -- 0 / -- 0 / -- 0 / -- 2 / 8372
  11. 4 aarhrl2 0 / -- 0 / -- 1 / 5076 1 / 5109 0 / -- 0 / -- 0 / -- 2 / 10185
  12. 5 yeoniverse 0 / -- 0 / -- 1 / 5154 1 / 5153 0 / -- 0 / -- 0 / -- 2 / 10307
  13. 6 chipi2302 3 / 8748 1 / 8714 10 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 17462
  14. 7 gandori3 0 / -- 0 / -- 1 / 5224 0 / -- 0 / -- 0 / -- 0 / -- 1 / 5224
  15. 8 021014sarah 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 0 / 0
  16. """
  17. info = info.splitlines(keepends = True)
  18. if info[0] == "\n": info.pop(0)
  19.  
  20. # 랜덤 시드
  21. mod = 4294967296 # 2^32
  22. seed_string = "251119"
  23. random_seed = int.from_bytes(hashlib.sha256(seed_string.encode()).digest(), 'big') % mod
  24. np.random.seed(random_seed)
  25.  
  26. participants = {}
  27. for participant in info:
  28. participant = participant.split('\t')
  29. user = participant[1]
  30. corrects = int(participant[-1].split(' / ')[0])
  31. if user in participants:
  32. participants[user] = max(participants[user], corrects + 3)
  33. else: participants[user] = corrects + 3
  34.  
  35. # 추첨 명단 제외 리스트
  36. except_list = ['aerae','likescape']
  37. for except_user in except_list:
  38. try:
  39. participants.pop(except_user)
  40. except:
  41. pass
  42.  
  43. # 추첨 확률 설정
  44. winner_percent = [0] * len(participants)
  45. correct_problems_sum = sum(participants.values())
  46.  
  47. for i, corrects in enumerate(list(participants.values())):
  48. winner_percent[i] = corrects / correct_problems_sum
  49.  
  50. print(f'랜덤 시드: {seed_string}')
  51. print(f'{len(participants)}명 {list(participants.keys())}')
  52. # print(f'맞은 문제 개수: {list(participants.values())}')
  53. # print(f'확률: {winner_percent}')
  54.  
  55. # 당첨자
  56. winner = np.random.choice(list(participants.keys()), winner_num, replace = False, p = winner_percent) \
  57. if winner_num < len(participants) else list(participants.keys())
  58. winner.sort()
  59. print(f'당첨자: {winner}')# your code goes here
Success #stdin #stdout 1.08s 41220KB
stdin
Standard input is empty
stdout
랜덤 시드: 251119
8명 [' glnthd02', ' bwgreen', ' psh030122', ' aarhrl2', ' yeoniverse', ' chipi2302', ' gandori3', ' 021014sarah']
당첨자: [' aarhrl2' ' bwgreen' ' glnthd02' ' psh030122' ' yeoniverse']