코딩/백준 문제 (브론즈)

[백준/25304/파이썬] 영수증 풀이

룻밤 2023. 1. 22. 23:30

리스트를 활용한 풀이

x = int(input())    # 총액수
y = int(input())    # 종류
c = []  # total을 위한 리스트


for i in range(y):  # 0~y-1개만큼 반복
    a, b = map(int, input().split())   # 개별 가격, 개수   
    c.append(a * b) # 리스트에 a*b 값을 요소로 추가
    
if x == sum(c): # 총액수가 리스트의 total과 같다면
    print("Yes")    # Yes출력
else:   # 다르다면
    print("No") # No 출력

 

+= 기호를 활용한 풀이

x = int(input())    # 총액수
y = int(input())    # 종류
c = 0   # total 변수


for i in range(y):  # 0~y-1개만큼 반복
    a, b = map(int, input().split())   # 개별 가격, 개수   
    c += a*b  # y반복횟수만큼 c를 누적 덧셈 = total
    
if x == c: # 총액수가 total변수와 같다면
    print("Yes")    # Yes출력
else:   # 다르다면
    print("No") # No 출력