[25304] 영수증
| Algorithms / 백준 문제 풀이 모음 # Python, Bronze 5
백준 문제 풀이
25304번: 영수증
해설
총 금액과 영수증의 금액이 일치하지 않으면 No 를 일치하면 Yes를 출력한다. 첫 입력으로 total (총 금액)을 입력 받는다. 이후 영수증에 종류 수 N 에 따라서 입력을 받는다. for i in range(item_count): cost, count = map(int, input().split()) 이때 입력을 따로 저장해두지 않고 입력 받는 즉시 total (총 금액)에서 빼면 코드를 좀더 줄일 수 있다. 결과적으로 총 금액과 일치하는 지 아닌지 체크하면 되기 때문에 N(물건 개수) 를 전부 입력 받은 뒤 total 이 0 인지 체크하면 된다. if total == 0: print('Yes') else: print('No')답안
if __name__ == '__main__': total = int(input()) item_count = int(input()) for i in range(item_count): cost, count = map(int, input().split()) total -= cost*count if total == 0: print('Yes') else: print('No')