-
[23056] 참가자 명단 (Python)[Python] 알고리즘/Silver 2021. 11. 9. 19:58
[문제]
https://www.acmicpc.net/problem/23056
알고리즘 분류는 문자열, 정렬 입니다.
참가자 명단은 학급 오름차순, 이름의 길이, 사전 순 순서로 정렬합니다. (다중 정렬 필요)
[코드]
import sys N, M = map(int, sys.stdin.readline().split()) li = list() dt = dict() while True: join = sys.stdin.readline().rstrip() if join == "0 0": break join = join.split() dt[join[0]] = dt.get(join[0], 0) + 1 if dt[join[0]] <= M: li.append(join) li = sorted(li, key=lambda x: (int(x[0]), len(x[1]), x[1])) blue = list() white = list() for i in range(len(li)): if int(li[i][0]) % 2 == 0: white.append(" ".join(li[i])) else: blue.append(" ".join(li[i])) for i in blue: print(i) for i in white: print(i)
'[Python] 알고리즘 > Silver' 카테고리의 다른 글
[1748] 수 이어 쓰기 1 (Python) (0) 2021.11.11 [17479] 정식당 (Python) (0) 2021.11.10 [18115] 카드 놓기 (Python) (0) 2021.11.08 [13414] 수강신청 (Python) (0) 2021.11.05 [9996] 한국이 그리울 땐 서버에 접속하지 (Python) (0) 2021.11.04