import numpy as np import hashlib # 추첨 인원수 winner_num = 3 # BOJ 연습란을 텍스트로 긁어오면 됩니다 (랭킹, 아이디, A, B, C, ... 맨 윗줄 제외하고) info = """ 1 glnthd02 1 / 322 1 / 325 1 / 341 2 / 397 1 / 381 1 / 364 3 / 833 7 / 893 2 import1234 1 / 6875 1 / 5838 2 / 3570 1 / 2742 1 / 1831 1 / 321 3 / 144 7 / 6935 3 h1234000 3 / 861 1 / 868 1 / 1116 1 / 1157 2 / 1275 7 / 1349 0 / -- 6 / 1529 4 csm8717 3 / 1170 3 / 1190 1 / 1204 1 / 8559 31 / -- 0 / -- 0 / -- 4 / 8639 5 hms0510 1 / 925 2 / 933 1 / 954 0 / -- 0 / -- 0 / -- 0 / -- 3 / 974 6 jjhlemon 1 / 958 5 / 5761 1 / 5818 0 / -- 0 / -- 0 / -- 0 / -- 3 / 5898 7 kdh9158kdh 1 / 2309 2 / 2341 2 / 5971 0 / -- 0 / -- 0 / -- 0 / -- 3 / 6011 8 tim0929 1 / 3 1 / 41 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 41 9 rlawoaks 1 / 4134 2 / 4138 1 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 4158 10 dlwjdals2002 3 / 4309 0 / -- 1 / 4348 0 / -- 0 / -- 0 / -- 0 / -- 2 / 4388 11 bwgreen 1 / 4982 1 / 4985 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 4985 12 fish13031e 1 / 219 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 1 / 219 13 siubeom 2 / 1105 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 1 / 1125 14 motsuni04 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 1357 0 / -- 1 / 1377 15 aerae 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 1 / 3307 0 / -- 1 / 3307 """ info = info.splitlines(keepends = True) if info[0] == "\n": info.pop(0) # 랜덤 시드 mod = 4294967296 # 2^32 seed_string = "Hello, AlKon!" 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'] 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
Standard input is empty
랜덤 시드: Hello, AlKon! 15명 [' glnthd02', ' import1234', ' h1234000', ' csm8717', ' hms0510', ' jjhlemon', ' kdh9158kdh', ' tim0929', ' rlawoaks', ' dlwjdals2002', ' bwgreen', ' fish13031e', ' siubeom', ' motsuni04', ' aerae'] 맞은 문제 개수: [10, 10, 9, 7, 6, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4] 확률: [0.1111111111111111, 0.1111111111111111, 0.1, 0.07777777777777778, 0.06666666666666667, 0.06666666666666667, 0.06666666666666667, 0.05555555555555555, 0.05555555555555555, 0.05555555555555555, 0.05555555555555555, 0.044444444444444446, 0.044444444444444446, 0.044444444444444446, 0.044444444444444446] 당첨자: [' h1234000' ' kdh9158kdh' ' tim0929']