[BOJ]백준#3443 Silver 5 Reaux! Sham! Beaux!(Python, 파이썬)

임준성·2022년 9월 23일
0

백준 Algorithm

목록 보기
58/59
post-thumbnail

백준 3443번
https://www.acmicpc.net/problem/3443

문제



후기

⏰ 풀이시간 30분 ++⏰

맞힌 사람이 많지 않은 문제를 풀기 위해 풀은 사람이 적은 순으로 정렬해서

찾은 문제의 13번째다.

문제가 까다로운 것은 아니지만, 구현을 정말 실수없이 일일이 많이 해야하는 문제였다.

문제에서 요구하는 바는, 가위바위보를 하는데, 각 나라의 가위 , 바위 , 보를

그 나라의 언어로 해석해서 누가 이겼는지 결과를 내고, 통계를 내는 문제였다.

문제에서 주어진 표를 미리 Dictinoary로 (정말 노동이다 .. 하나하나 해야함 )

전부 구현해두고,

1점 일때만 point로 출력, 나머지의 경우에는 points로 출력 해야하며,

case와 case 사이에서 "-" 이 입력될 땐 해당 게임이 종료되고, "." 이 입력될 땐 반복 자체가 종료된다.

import sys
input= sys.stdin.readline

li = { "Kamen":1, "Rock" : 1 , "Pierre":1 , "Stein":1, "Ko":1, "Koe":1, "Sasso":1, "Roccia":1, "Guu":1, "Kamien":1, "Piedra":1,
"Nuzky":2 , "Scissors":2, "Ciseaux":2, "Schere":2, "Ollo":2, "Olloo":2, "Forbice":2, "Choki":2, "Nozyce":2, "Tijera":2,
"Papir":3, "Paper":3 , "Feuille":3, "Papier":3, "Carta":3, "Rete":3, "Paa":3, "Papier":3, "Papel":3}
#문제에서 주어진 각 나라별 가위바위보에 대한 값을 dictionary로 저장한다
cnt = 1 #몇번째 게임인가
error = 0
  
while True:
    name = input().rstrip().split()
    name2= input().rstrip().split()
    name = name[1]
    name2 = name2[1]
    name1_score=  0
    name2_score=  0

    while True:
        game = input().rstrip().split()
        if game[0] == "-": #-일땐 해당라운드의 게임종료
            break
        if game[0] == ".": #.일땐 반복 종료
            error += 1
            break

        a = li.get(game[0]) #가위인지 바위인지를 가져온다.
        b = li.get(game[1]) #가위인지 바위인지를 가져온다.

        if a == 1 and b==2: #가위바위보의 모든 경우에 대해 승패를 정한다.
            name1_score +=1
        elif a== 1 and b==3:
            name2_score += 1
        elif a== 2 and b==1:
            name2_score += 1
        elif a== 2 and b==3:
            name1_score += 1
        elif a== 3 and b==1:
            name1_score += 1
        elif a== 3 and b == 2:
            name2_score += 1


    print("Game #{}:".format(cnt))
    if name1_score !=1: #1포인트일때가 아니면 points
        print("{}: {} points".format(name, name1_score))
    else:
        print("{}: {} point".format(name, name1_score))
    if name2_score !=1: #1포인트는 point
        print("{}: {} points".format(name2, name2_score))
    else:
        print("{}: {} point".format(name2, name2_score))

    if name1_score == name2_score:
        print("TIED GAME")
    elif name1_score > name2_score:
        print("WINNER: {}".format(name))
    elif name2_score > name1_score:
        print("WINNER: {}".format(name2))
    
    cnt += 1
    print()
    if error == 1:
        break
profile
아무띵크 있이

0개의 댓글