코딩테스트/백준(JAVA)

백준 코딩테스트 3-4-25304 영수증 코딩 문제 java로 푸는 방법

쏠솔랄라 2023. 3. 15. 09:54

 

 

백준 코딩테스트 단계별로 풀어보기

3단계 반복문 4단계 25304 영수증 문제입니다

 

 

https://www.acmicpc.net/problem/25304

 

25304번: 영수증

준원이는 저번 주에 살면서 처음으로 코스트코를 가 봤다. 정말 멋졌다. 그런데, 몇 개 담지도 않았는데 수상하게 높은 금액이 나오는 것이다! 준원이는 영수증을 보면서 정확하게 계산된 것

www.acmicpc.net

 

https://www.acmicpc.net/step

 

단계별로 풀어보기

단계별은 @jh05013님이 관리하고 계십니다. 단계제목설명정보총 문제내가 맞은 문제1입출력과 사칙연산입력, 출력과 사칙연산을 연습해 봅시다. Hello World!132조건문if 등의 조건문을 사용해 봅시다

www.acmicpc.net

 

 


 

 

 

 

문제
준원이는 저번 주에 살면서 처음으로 코스트코를 가 봤다. 정말 멋졌다.
그런데, 몇 개 담지도 않았는데 수상하게 높은 금액이 나오는 것이다! 
준원이는 영수증을 보면서 정확하게 계산된 것이 맞는지 확인해보려 한다.
영수증에 적힌,구매한 각 물건의 가격과 개수구매한 물건들의 총 금액을 보고, 구매한 물건의 가격과 개수로 계산한 총 금액이 영수증에 적힌 총 금액과 일치하는지 검사해보자.

입력
첫째 줄에는 영수증에 적힌 총 금액 X가 주어진다.
둘째 줄에는 영수증에 적힌 구매한 물건의 종류의 수 N이 주어진다.
이후 N개의 줄에는 각 물건의 가격 a와 개수 b가 공백을 사이에 두고 주어진다.

출력
구매한 물건의 가격과 개수로 계산한 총 금액이 영수증에 적힌 총 금액과 일치하면 Yes를 출력한다.
일치하지 않는다면 No를 출력한다.

제한
1 ≤ X ≤1000000000
1 ≤ N ≤ 100
1 ≤ a ≤ 1000000  
1 ≤ b ≤ 10 

 

 

정답

import java.util.Scanner;

public abstract class Main {

public static void main(String[] args) {

 

Scanner sc = new Scanner(System.in);

int X = sc.nextInt();

int N = sc.nextInt();

int sum = 0;

 

for (int i=1; i<=N; i++) {

int a = sc.nextInt();

int b = sc.nextInt();

sum += a*b;

}

 

if (X==sum) {

System.out.println("Yes");

} else {

System.out.println("No");

}

}

}

 

=>

조건 적용 안 하고 그대로 입출력값 논리만 적용한 문제 

 

 

 


 

 

1-1-2557 Hello World https://developernew.tistory.com/41 <- 백준 답지 제출 방법
1-2-1000 A+B https://developernew.tistory.com/42
1-3-1001 A-B https://developernew.tistory.com/43
1-4-10998 AXB https://developernew.tistory.com/44
1-5-1008 A/B https://developernew.tistory.com/45
1-6-10869 사칙연산 https://developernew.tistory.com/46
1-7-10926 ??! https://developernew.tistory.com/47
1-8-18108 1998년생인 내가 태국에서는 2541년생?! https://developernew.tistory.com/48
1-9-10430 나머지 https://developernew.tistory.com/49
1-10-2588 곱셈 https://developernew.tistory.com/50
1-11-11382 꼬마 정민 https://developernew.tistory.com/51
1-12-10171 고양이 https://developernew.tistory.com/52
1-13-10172 개 https://developernew.tistory.com/53

2-1-1330 두 수 비교하기 https://developernew.tistory.com/54
2-2-9498 시험 성적 https://developernew.tistory.com/55
2-3-2753 윤년 https://developernew.tistory.com/56
2-4-14681 사분면 고르기 https://developernew.tistory.com/61
2-5-2884 알람 시계 https://developernew.tistory.com/68
2-6-2525 오븐 시계 https://developernew.tistory.com/69
2-7-2480 주사위 https://developernew.tistory.com/72

3-1-2739 구구단 https://developernew.tistory.com/73
3-2-10950 A+B - 3 https://developernew.tistory.com/75
3-3-8393 합 https://developernew.tistory.com/77