ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Kotlin ๐Ÿฌ ๋ฐฑ์ค€ 3๋‹จ๊ณ„ :: 25304 ๋ฒˆ
    2023. 3. 24. 15:14
    ๋ฐ˜์‘ํ˜•

    ์˜์ˆ˜์ฆ

    ๋ฌธ์ œ   |

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

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

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

      - ๊ตฌ๋งคํ•œ ๋ฌผ๊ฑด๋“ค์˜ ์ด ๊ธˆ์•ก

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

     

    ์ž…๋ ฅ   |

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

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

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

     

    ์ถœ๋ ฅ   |

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

    ์ œํ•œ  |  - 1 ≤ X ≤ 1,000,000,000  - 1 ≤ N ≤ 100  - 1 ≤ a ≤ 1,000,000  - 1 ≤ b ≤ 10

     

     

     

    ํ’€์ด  |

      Scanner๋ฅผ ์ด์šฉํ•ด ์ž…๋ ฅ์„ ๋ฐ›์•„ ์ถœ๋ ฅ

     

     

    ๋‹ต์•ˆ  |

    import java.util.Scanner
    
    fun main() = with(Scanner(System.`in`)) {
        val total = nextInt()
        val num = nextInt()
        var result = 0
        
        for (i in 1..num) {
            var a = nextInt()
            var b = nextInt()
            
            result += a * b
        }
        
        if (total == result) {
            print("Yes")
        } else {
            print("No")
        }
    }
    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€

Designed by Tistory.