코테/백준
[백준/JAVA] 25304번: 영수증
imname1am
2023. 3. 16. 14:41
반응형
🔺 문제
25304번: 영수증
준원이는 저번 주에 살면서 처음으로 코스트코를 가 봤다. 정말 멋졌다. 그런데, 몇 개 담지도 않았는데 수상하게 높은 금액이 나오는 것이다! 준원이는 영수증을 보면서 정확하게 계산된 것
www.acmicpc.net
🔺 코드
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException{
var br = new BufferedReader(new InputStreamReader(System.in));
var bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
int X = Integer.parseInt(br.readLine());
int N = Integer.parseInt(br.readLine());
int total = 0;
for(int i=0; i < N ; i++) {
st = new StringTokenizer(br.readLine(), " "); // 한 글자씩
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
total += a * b;
}
if(total == X) bw.write("Yes");
else bw.write("No");
bw.flush();
bw.close();
}
}
- st 위치 잘 기억해두기!
- 출력 시 BufferedWriter를 이용해 보았다.
반응형