충분히 쌓여가는
백준[Java] 25304번 영수증 본문
https://www.acmicpc.net/problem/25304
문제풀이 1
import java.util.Scanner;
public class _25304_1 {
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 = 0; i < N; i++) {
int a = sc.nextInt();
int b = sc.nextInt();
sum += a * b;
}
if (sum == X)
System.out.println("Yes");
else
System.out.println("No");
}
}
문제풀이 2
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class _25304_2 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int X = 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 a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
sum += a * b;
}
if (sum == X)
System.out.println("Yes");
else
System.out.println("No");
}
}
문제풀이 3
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class _25304_3 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int X = Integer.parseInt(br.readLine());
int N = Integer.parseInt(br.readLine());
int sum = 0;
for (int i = 0; i < N; i++) {
String[] str = br.readLine().split(" ");
int a = Integer.parseInt(str[0]);
int b = Integer.parseInt(str[1]);
sum += a * b;
}
if (sum == X)
System.out.println("Yes");
else
System.out.println("No");
}
}
'IT > Java[백준]' 카테고리의 다른 글
백준[Java] 11021번 A+B-7 (0) | 2023.02.20 |
---|---|
백준[Java] 8393번 합 (*문제는 쉽지만 시간초과에 대한 문제! 중요!) (2) | 2023.02.17 |
백준[Java] 8393번 합 (0) | 2023.02.16 |
백준[Java] 10950번 A+B-3 (0) | 2023.02.15 |
백준[Java] 2739번 구구단 (0) | 2023.02.15 |