fork 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 / 64 1 / 66 1 / 878 1 / 83 3 / 1150 2 / 919 2 / 1196 7 / 4356
  9. 2 bwgreen 1 / 750 1 / 895 6 / 1347 5 / 1562 2 / 3014 0 / -- 0 / -- 5 / 7568
  10. 3 hms0510 1 / 5467 2 / 5506 1 / 5514 3 / 5598 0 / -- 0 / -- 0 / -- 4 / 22085
  11. 4 dlwjdals2002 1 / 1111 3 / 1168 0 / -- 5 / 4491 0 / -- 0 / -- 0 / -- 3 / 6770
  12. 5 chipi2302 1 / 1138 1 / 1182 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 2320
  13. 6 gandori3 1 / 2802 0 / -- 4 / 2958 0 / -- 0 / -- 0 / -- 0 / -- 2 / 5760
  14. 7 upncol 0 / -- 0 / -- 1 / 6672 1 / 6661 0 / -- 0 / -- 0 / -- 2 / 13333
  15. 8 bakbakwanwan 1 / 5831 4 / -- 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 1 / 5831
  16. 9 kdh9158kdh 0 / -- 0 / -- 0 / -- 2 / 6602 0 / -- 0 / -- 0 / -- 1 / 6602
  17. 9 yeoniverse 0 / -- 0 / -- 1 / 6602 1 / -- 0 / -- 0 / -- 0 / -- 1 / 6602
  18. """
  19. info = info.splitlines(keepends = True)
  20. if info[0] == "\n": info.pop(0)
  21.  
  22. # 랜덤 시드
  23. mod = 4294967296 # 2^32
  24. seed_string = "251111"
  25. random_seed = int.from_bytes(hashlib.sha256(seed_string.encode()).digest(), 'big') % mod
  26. np.random.seed(random_seed)
  27.  
  28. participants = {}
  29. for participant in info:
  30. participant = participant.split('\t')
  31. user = participant[1]
  32. corrects = int(participant[-1].split(' / ')[0])
  33. if user in participants:
  34. participants[user] = max(participants[user], corrects + 3)
  35. else: participants[user] = corrects + 3
  36.  
  37. # 추첨 명단 제외 리스트
  38. except_list = ['aerae','likescape']
  39. for except_user in except_list:
  40. try:
  41. participants.pop(except_user)
  42. except:
  43. pass
  44.  
  45. # 추첨 확률 설정
  46. winner_percent = [0] * len(participants)
  47. correct_problems_sum = sum(participants.values())
  48.  
  49. for i, corrects in enumerate(list(participants.values())):
  50. winner_percent[i] = corrects / correct_problems_sum
  51.  
  52. print(f'랜덤 시드: {seed_string}')
  53. print(f'{len(participants)}명 {list(participants.keys())}')
  54. # print(f'맞은 문제 개수: {list(participants.values())}')
  55. # print(f'확률: {winner_percent}')
  56.  
  57. # 당첨자
  58. winner = np.random.choice(list(participants.keys()), winner_num, replace = False, p = winner_percent) \
  59. if winner_num < len(participants) else list(participants.keys())
  60. winner.sort()
  61. print(f'당첨자: {winner}')# your code goes here
Success #stdin #stdout 0.81s 41548KB
stdin
Standard input is empty
stdout
랜덤 시드: 251111
10명 [' glnthd02', ' bwgreen', ' hms0510', ' dlwjdals2002', ' chipi2302', ' gandori3', ' upncol', ' bakbakwanwan', ' kdh9158kdh', ' yeoniverse']
당첨자: [' bwgreen' ' glnthd02' ' kdh9158kdh' ' upncol' ' yeoniverse']