방명록
- 백준 java) #25304번 : 영수증2023년 04월 06일 17시 45분 33초에 업로드 된 글입니다.작성자: Moonsu99
백준 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"); } } }
*출력
'놀이터' 카테고리의 다른 글
프로그래머스 - 코드 처리하기 (0) 2023.10.28 백준 java) #25314번 : 코딩은 체육과목입니다. (0) 2023.04.06 백준 java) #2480번 : 주사위 세개 (0) 2023.04.06 백준 java) #2525번 : 오븐시계 (0) 2023.04.06 백준 java) #2884번 : 알람시계 (0) 2023.04.06 다음글이 없습니다.이전글이 없습니다.댓글