SWEA

[python][SWEA][D3] 3142. 영준이와 신비한 뿔의 숲

haju 2023. 5. 12. 16:41

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&problemLevel=3&contestProbId=AV_6xWk6sbADFAWS&categoryId=AV_6xWk6sbADFAWS&categoryType=CODE&problemTitle=&orderBy=PASS_RATE&selectCodeLang=PYTHON&select-1=3&pageSize=10&pageIndex=5 

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

✅ 풀이

  • 트윈혼의 뿔이 2개 이므로, 한마리씩 있는지 확인하면서 전체 뿔 개수를 줄여나간다.
  • 위의 조건을 한 번씩 수행하면서, 만약에 트윈혼의 수 + 나머지 n의 수(유니콘의 뿔은 하나이므로) 값이 m마리의 수와 같다면 반복문을 중단하고 값 출력하기
T=int(input())

for test_case in range(1,T+1):
    n,m=map(int,input().split())

    twin=0
    while n!=0:
        if twin+n==m:
            break
        else:
            n-=2
            twin+=1
    print("#%d %d %d" %(test_case,n,twin))