import numpy as np
import hashlib
# 추첨 인원수
winner_num = 5
# BOJ 연습란을 텍스트로 긁어오면 됩니다 (랭킹, 아이디, A, B, C, ... 맨 윗줄 제외하고)
info = """
1 glnthd02 1 / 4400 1 / 4411 1 / 4401 1 / 4434 2 / 4512 4 / 4629 0 / -- 6 / 26787
2 bwgreen 1 / 8572 1 / 8579 1 / 8579 1 / 8599 3 / 8679 1 / 8650 0 / -- 6 / 51658
3 psh030122 3 / 2831 0 / -- 2 / 5541 0 / -- 0 / -- 0 / -- 0 / -- 2 / 8372
4 aarhrl2 0 / -- 0 / -- 1 / 5076 1 / 5109 0 / -- 0 / -- 0 / -- 2 / 10185
5 yeoniverse 0 / -- 0 / -- 1 / 5154 1 / 5153 0 / -- 0 / -- 0 / -- 2 / 10307
6 chipi2302 3 / 8748 1 / 8714 10 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 17462
7 gandori3 0 / -- 0 / -- 1 / 5224 0 / -- 0 / -- 0 / -- 0 / -- 1 / 5224
8 021014sarah 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 0 / 0
"""
info = info.splitlines(keepends = True)
if info[0] == "\n": info.pop(0)
# 랜덤 시드
mod = 4294967296 # 2^32
seed_string = "251119"
random_seed = int.from_bytes(hashlib.sha256(seed_string.encode()).digest(), 'big') % mod
np.random.seed(random_seed)
participants = {}
for participant in info:
participant = participant.split('\t')
user = participant[1]
corrects = int(participant[-1].split(' / ')[0])
if user in participants:
participants[user] = max(participants[user], corrects + 3)
else: participants[user] = corrects + 3
# 추첨 명단 제외 리스트
except_list = ['aerae','likescape']
for except_user in except_list:
try:
participants.pop(except_user)
except:
pass
# 추첨 확률 설정
winner_percent = [0] * len(participants)
correct_problems_sum = sum(participants.values())
for i, corrects in enumerate(list(participants.values())):
winner_percent[i] = corrects / correct_problems_sum
print(f'랜덤 시드: {seed_string}')
print(f'{len(participants)}명 {list(participants.keys())}')
# print(f'맞은 문제 개수: {list(participants.values())}')
# print(f'확률: {winner_percent}')
# 당첨자
winner = np.random.choice(list(participants.keys()), winner_num, replace = False, p = winner_percent) \
if winner_num < len(participants) else list(participants.keys())
winner.sort()
print(f'당첨자: {winner}')# your code goes here