본문 바로가기

백준 문제풀기/JAVA

[백준 25304 JAVA 자바] 영수증

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        int price = Integer.parseInt(br.readLine()); //예상 합
        
        int n = Integer.parseInt(br.readLine()); // 물건 종류의 수
        
        int sum = 0; // 앞으로 물건들의 합입니다
        
        for (int i=0; i<n; i++) { //물건 종류의 수 만큼 반복합니다
        	StringTokenizer st = new StringTokenizer(br.readLine());
        	
        	int product = Integer.parseInt(st.nextToken());
        	int amount = Integer.parseInt(st.nextToken());
        	
        	sum += product * amount; // 물건의 가격*갯수를 더해줍니다
        }
        
        if(sum==price) { // 일치하면 Yes를 출력합니다
        	System.out.println("Yes");
        }else {
        	System.out.println("No");
        }
    }
}