ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Kotlin ๐Ÿฌ ๋ฐฑ์ค€ 14๋‹จ๊ณ„ :: 14425 ๋ฒˆ
    2024. 3. 1. 17:53
    ๋ฐ˜์‘ํ˜•

    ๋ฌธ์ž์—ด ์ง‘ํ•ฉ

    ๋ฌธ์ œ   |

      ์ด N๊ฐœ์˜ ๋ฌธ์ž์—ด๋กœ ์ด๋ฃจ์–ด์ง„ ์ง‘ํ•ฉ S๊ฐ€ ์ฃผ์–ด์ง„๋‹ค.

      ์ž…๋ ฅ์œผ๋กœ ์ฃผ์–ด์ง€๋Š” M๊ฐœ์˜ ๋ฌธ์ž์—ด ์ค‘์—์„œ ์ง‘ํ•ฉ S์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” ๊ฒƒ์ด ์ด ๋ช‡ ๊ฐœ์ธ์ง€ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

     

    ์ž…๋ ฅ   |

      ์ฒซ์งธ ์ค„์— ๋ฌธ์ž์—ด์˜ ๊ฐœ์ˆ˜ N๊ณผ M (1 ≤ N ≤ 10,000, 1 ≤ M ≤ 10,000)์ด ์ฃผ์–ด์ง„๋‹ค.

      ๋‹ค์Œ N๊ฐœ์˜ ์ค„์—๋Š” ์ง‘ํ•ฉ S์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” ๋ฌธ์ž์—ด๋“ค์ด ์ฃผ์–ด์ง„๋‹ค.

      ๋‹ค์Œ M๊ฐœ์˜ ์ค„์—๋Š” ๊ฒ€์‚ฌํ•ด์•ผ ํ•˜๋Š” ๋ฌธ์ž์—ด๋“ค์ด ์ฃผ์–ด์ง„๋‹ค.

      ์ž…๋ ฅ์œผ๋กœ ์ฃผ์–ด์ง€๋Š” ๋ฌธ์ž์—ด์€ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, ๊ธธ์ด๋Š” 500์„ ๋„˜์ง€ ์•Š๋Š”๋‹ค. ์ง‘ํ•ฉ S์— ๊ฐ™์€ ๋ฌธ์ž์—ด์ด ์—ฌ๋Ÿฌ ๋ฒˆ ์ฃผ์–ด์ง€๋Š” ๊ฒฝ์šฐ๋Š” ์—†๋‹ค.

     

    ์ถœ๋ ฅ   |

      ์ฒซ์งธ ์ค„์— M๊ฐœ์˜ ๋ฌธ์ž์—ด ์ค‘์— ์ด ๋ช‡ ๊ฐœ๊ฐ€ ์ง‘ํ•ฉ S์— ํฌํ•จ๋˜์–ด ์žˆ๋Š”์ง€ ์ถœ๋ ฅํ•œ๋‹ค.

     

     

    ํ’€์ด  |

      M๊ฐœ์˜ ๋ฌธ์ž์—ด ์ง‘ํ•ฉ์„ for๋ฌธ์„ ๋Œ๋ ค N๊ฐœ์˜ S ์ง‘ํ•ฉ array์— ํฌํ•จ๋˜์–ด์žˆ๋Š”์ง€ ํ™•์ธ ํ›„ ํฌํ•จ๋˜๋ฉด 1 ์”ฉ ๋”ํ•œ๋‹ค.

     

     

    ๋‹ต์•ˆ  |

    import java.io.BufferedReader
    import java.io.InputStreamReader
    
    fun main() {
        val br = BufferedReader(InputStreamReader(System.`in`))
    
        val (N, M) = br.readLine().split(" ").map { it.toInt() }
        val sArr = mutableSetOf<String>()
        repeat(N) {
            sArr.add(br.readLine())
        }
        val mArr = mutableListOf<String>()
        repeat(M) {
            mArr.add(br.readLine())
        }
    
        var result = 0
        for (i in mArr.indices) {
            if (mArr[i] in sArr) {
                result++
            }
        }
    
        print(result)
    }
    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€

Designed by Tistory.