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 bwgreen 1 / 3232 1 / 3243 1 / 3253 1 / 3258 1 / 3364 5 / 3473 1 / 6299 7 / 26122
  9. 2 glnthd02 2 / 4051 2 / 4074 1 / 4059 2 / 4099 2 / 4150 22 / 4732 1 / 8215 7 / 33380
  10. 3 psh030122 1 / 3043 1 / 3064 1 / 7606 1 / 8592 0 / -- 0 / -- 0 / -- 4 / 22305
  11. 4 hms0510 1 / 2469 1 / 2485 2 / 2559 0 / -- 0 / -- 0 / -- 0 / -- 3 / 7513
  12. 5 yuujeong0816 1 / 3935 0 / -- 5 / -- 0 / -- 1 / 4229 0 / -- 0 / -- 2 / 8164
  13. 6 likescape 1 / 241 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 1 / 241
  14. 7 chipi2302 1 / 2578 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 1 / 2578
  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 = "251124"
  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 0.78s 41536KB
stdin
Standard input is empty
stdout
랜덤 시드: 251124
8명 [' bwgreen', ' glnthd02', ' psh030122', ' hms0510', ' yuujeong0816', ' likescape', ' chipi2302', ' 021014sarah']
당첨자: [' chipi2302' ' glnthd02' ' hms0510' ' psh030122' ' yuujeong0816']