728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

์ค€์›์ด๋Š” ์ €๋ฒˆ ์ฃผ์— ์‚ด๋ฉด์„œ ์ฒ˜์Œ์œผ๋กœ ์ฝ”์ŠคํŠธ์ฝ”๋ฅผ ๊ฐ€ ๋ดค๋‹ค. ์ •๋ง ๋ฉ‹์กŒ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ, ๋ช‡ ๊ฐœ ๋‹ด์ง€๋„ ์•Š์•˜๋Š”๋ฐ ์ˆ˜์ƒํ•˜๊ฒŒ ๋†’์€ ๊ธˆ์•ก์ด ๋‚˜์˜ค๋Š” ๊ฒƒ์ด๋‹ค! ์ค€์›์ด๋Š” ์˜์ˆ˜์ฆ์„ ๋ณด๋ฉด์„œ ์ •ํ™•ํ•˜๊ฒŒ ๊ณ„์‚ฐ๋œ ๊ฒƒ์ด ๋งž๋Š”์ง€ ํ™•์ธํ•ด๋ณด๋ ค ํ•œ๋‹ค.

์˜์ˆ˜์ฆ์— ์ ํžŒ,

  • ๊ตฌ๋งคํ•œ ๊ฐ ๋ฌผ๊ฑด์˜ ๊ฐ€๊ฒฉ๊ณผ ๊ฐœ์ˆ˜
  • ๊ตฌ๋งคํ•œ ๋ฌผ๊ฑด๋“ค์˜ ์ด ๊ธˆ์•ก

์„ ๋ณด๊ณ , ๊ตฌ๋งคํ•œ ๋ฌผ๊ฑด์˜ ๊ฐ€๊ฒฉ๊ณผ ๊ฐœ์ˆ˜๋กœ ๊ณ„์‚ฐํ•œ ์ด ๊ธˆ์•ก์ด ์˜์ˆ˜์ฆ์— ์ ํžŒ ์ด ๊ธˆ์•ก๊ณผ ์ผ์น˜ํ•˜๋Š”์ง€ ๊ฒ€์‚ฌํ•ด๋ณด์ž.

์ž…๋ ฅ

์ฒซ์งธ ์ค„์—๋Š” ์˜์ˆ˜์ฆ์— ์ ํžŒ ์ด ๊ธˆ์•ก X๊ฐ€ ์ฃผ์–ด์ง„๋‹ค.

๋‘˜์งธ ์ค„์—๋Š” ์˜์ˆ˜์ฆ์— ์ ํžŒ ๊ตฌ๋งคํ•œ ๋ฌผ๊ฑด์˜ ์ข…๋ฅ˜์˜ ์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค.

์ดํ›„ ๊ฐœ์˜ ์ค„์—๋Š” ๊ฐ ๋ฌผ๊ฑด์˜ ๊ฐ€๊ฒฉ a์™€ ๊ฐœ์ˆ˜ ๊ฐ€ ๊ณต๋ฐฑ์„ ์‚ฌ์ด์— ๋‘๊ณ  ์ฃผ์–ด์ง„๋‹ค.

์ถœ๋ ฅ

๊ตฌ๋งคํ•œ ๋ฌผ๊ฑด์˜ ๊ฐ€๊ฒฉ๊ณผ ๊ฐœ์ˆ˜๋กœ ๊ณ„์‚ฐํ•œ ์ด ๊ธˆ์•ก์ด ์˜์ˆ˜์ฆ์— ์ ํžŒ ์ด ๊ธˆ์•ก๊ณผ ์ผ์น˜ํ•˜๋ฉด Yes๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. ์ผ์น˜ํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด No๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

 

import java.util.Scanner;

public class Solution25304 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X,N,a,b;
		X = sc.nextInt();
		N = sc.nextInt();
		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");
				}
			}
		}

๋ธ”ํƒœ๊ธฐ๋ฅผ ๊ทน๋ณตํ•˜๊ณ  ๋‹ค์‹œ ๋Œ์•„์™”๋‹ค^^ ๋ง‰์ƒ ํ•˜๋ฉด ์žฌ๋ฐŒ๋Š”๋ฐ ์ฑ…์ƒ ์•ž์— ์•‰๊ธฐ๊นŒ์ง€ ์‹œ๊ฐ„์ด ๋„ˆ๋ฌด ์˜ค๋ž˜ ๊ฑธ๋ฆฐ๋‹ค..

์–ผ๋ฅธ ์Šคํ„ฐ๋””๋ฅผ ํ•ด์•ผํ•˜์ง€ ์‹ถ๋‹ค ใ…œ ์˜ค๋Š˜๋ถ€ํ„ฐ ๋‹ค์‹œ ๋ฐฑ์ค€ 1์ผ 1๋ฌธ์ œ๋Š” ๋ฌด์กฐ๊ฑด ํ’€์–ด์•ผ์ง€!! ์•ˆ ์˜ฌ๋ผ์˜ค๋ฉด ํ˜ผ๋‚ด์ฃผ3..

 

 

์ด ๋ฌธ์ œ๋Š” ํŠน์ดํ•˜๊ฒŒ yes/no๋กœ ์ถœ๋ ฅํ•˜๋Š” ๋ฌธ์ œ์˜€๋‹ค 

ํฌ๊ฒŒ ์–ด๋ ค์šด ๋ฌธ์ œ๋Š” ์•„๋‹ˆ์ง€๋งŒ ์•„์ง๋„ ๋ญ”๊ฐ€ +=์„ ์“ฐ๋Š”๊ฑธ ์ž˜ ๊นŒ๋จน๋Š”๊ฑฐ ๊ฐ™๋‹ค..

 

 

๋‹ค๋ฅธ๋ถ„๋“ค์€ ์–ด๋–ป๊ฒŒ ํ’€์—ˆ๋Š”์ง€ ๊ถ๊ธˆํ•ด์„œ ๋‹ค๋ฅธ ๋ธ”๋กœ๊ทธ๋ฅผ ์ฐพ์•„๋ณด์•˜๋‹ค!

import java.util.Scanner;

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

        Scanner sc = new Scanner(System.in);

        int total =  sc.nextInt();
        int count = sc.nextInt();

        for(int i = 0; i< count; i++){
            int price = sc.nextInt();
            int num = sc.nextInt();

            total = total - (price * num);
        }

        if(total == 0) System.out.println("Yes");
        else System.out.println("No");


    }
}

์ด๋ถ„์€ ์ „์ฒด๊ฐ’์—์„œ ์ข…๋ฅ˜์˜ ์ˆ˜์™€ ๊ฐ’์„ ๊ณฑํ•œ๊ฐ’์„ ๋บ€๊ฐ’์ด 0์ด๋‹ค๋ฅผ ์ด์šฉํ•ด์„œ ๋ฌธ์ œ๋ฅผ ํ‘ธ์…จ๋‹ค๐Ÿ‘

๋‹ค๋“ค ์ƒ๊ฐํ•˜๋Š”๊ฒŒ ๋‹ฌ๋ผ์„œ ์žฌ๋ฐŒ๋Š”๊ฑฐ ๊ฐ™๋‹ค๐Ÿ˜Š๐Ÿ˜Š

๋‚ด์ผ๋ถ€ํ„ด ์ •์ฒ˜๊ธฐ ์‹ค๊ธฐ ๊ณต๋ถ€ํ•œ๊ฒƒ๋„ ์˜ฌ๋ฆด๊ฑฐ๋‹ค.. ์•„๋งˆ๋‘...

728x90
๋ฐ˜์‘ํ˜•

+ Recent posts