🍊Algorithm

[λ°±μ€€ μ•Œκ³ λ¦¬μ¦˜] 25304번: 영수증 (Java, μžλ°” 풀이)

Nsso 2023. 5. 11. 15:21

문제

 

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

 

25304번: 영수증

μ€€μ›μ΄λŠ” μ €λ²ˆ 주에 μ‚΄λ©΄μ„œ 처음으둜 μ½”μŠ€νŠΈμ½”λ₯Ό κ°€ λ΄€λ‹€. 정말 λ©‹μ‘Œλ‹€. 그런데, λͺ‡ 개 담지도 μ•Šμ•˜λŠ”λ° μˆ˜μƒν•˜κ²Œ 높은 κΈˆμ•‘이 λ‚˜μ˜€λŠ” κ²ƒμ΄λ‹€! μ€€μ›μ΄λŠ” μ˜μˆ˜μ¦μ„ λ³΄λ©΄μ„œ μ •ν™•ν•˜κ²Œ κ³„μ‚°λœ 것

www.acmicpc.net

 


문제 μ„€λͺ…

 


문제 풀이

Scannerλ₯Ό μ‚¬μš©ν•˜μ—¬ κ΅¬ν˜„ν•˜μ˜€λ‹€.

 


μ½”λ“œ

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int X = sc.nextInt();
        int N = sc.nextInt();
        int a = 0;
        int b = 0;
        int sum = 0;

        for (int i = 0; i < N; i++) {
            a = sc.nextInt();
            b = sc.nextInt();
            sum += a * b;
        }

        if (sum == X) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}