[25304] 영수증

백준 문제 풀이

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')