놀이터
백준 java) #25304번 : 영수증
Moonsu99
2023. 4. 6. 17:45
백준 java) #25304번 : 영수증
간단한 문제이다.
영수증 총 금액, 물건 총 개수, 물건가격 * 개수로 계산한 총 금액, 개당물건가격,물건개수를 선언.
for 문과 if문만 써주면 된다.
*풀이
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int total = sc.nextInt(); // 영수증 총금액
int total_count = sc.nextInt(); //종류의 수
int cal = 0; // 물건가격과 개수로 계산한 총금액
for(int i=0; i<total_count;i++){
int a = sc.nextInt(); // 물건가격
int b = sc.nextInt();//물건개수
cal += a*b;// 물건의 가격과 개수로 계산한 금액을 더함
}
if(total == cal){
System.out.println("Yes");
}else {
System.out.println("No");
}
}
}
*출력