[BOJ][Python]딱지놀이 #14696

MEIN_FIGUR·2021년 7월 27일
0

SWEA_문제풀이

목록 보기
3/21

https://www.acmicpc.net/problem/14696

📌풀이


내가 쓴 풀이(성공)

from collections import defaultdict

number_of_round = int(input())
for round_num in range(number_of_round):
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    #딱지의 개수 부분 제거
    A.pop(0)
    B.pop(0)
    #각 모양의 갯수를 판단하기 위한 딕셔너리 생성
    A_dic, B_dic = defaultdict(int), defaultdict(int)
    for num in A:
        A_dic[num] += 1
    for num in B:
        B_dic[num] += 1
    
    #같은 모양 기준, 개수가 더 많은 쪽을 프린트
    #전부 다 같으면 D
    for shape in range(4,0,-1):
        if A_dic[shape] > B_dic[shape] :
            print('A')
            break
        elif A_dic[shape] < B_dic[shape] :
            print('B')
            break
    else :
        print('D')
  • 각 문자열을 받아와, 모양의 갯수를 저장하는 defaultdict에 저장
  • 각 모양의 갯수를 비교하여, 더 많은 쪽이 이긴것으로 판단
    • 이긴 쪽을 프린트, 비기면 D 출력

📌후기


문제에서 단계별 설명이 잘 되어있고, 예외케이스가 없어 무난하게 해결할 수 있었다.

profile
Growing Developer

0개의 댓글