๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm/Kotlin

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค • ์ฝ”ํ‹€๋ฆฐ] ์ง์‚ฌ๊ฐํ˜• ๋ณ„์ฐ๊ธฐ #12969

by ํ‚ค์œค 2023. 11. 18.

#12969

๐ŸŽ„ Question ?

https://school.programmers.co.kr/learn/courses/30/lessons/12969

fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(' ').map(String::toInt)
    println(a + b)
}

๐Ÿงฉ Thought Process

  1. *๋ฅผ a๋ฒˆ ์ ๊ณ 
    > ์ด๊ฑฐ ํ•  ๋–„ "๋ฌธ์ž์—ด"*(์ˆซ์ž) ์‚ฌ์šฉํ•˜๋ฉด ๋ฌธ์ž์—ด์ด ์ˆซ์ž๋งŒํผ ๋ฐ˜๋ณต๋˜๋Š” ๊ฑธ๋กœ ์ž‘์„ฑํ–ˆ๋Š”๋ฐ ์ฝ”ํ‹€๋ฆฐ์„ ์“ธ ๋•Œ์—๋Š” ๋ฌธ์ž์—ด ๊ณฑ์…ˆ์ด ์„ฑ๋ฆฝํ•˜์ง€ ์•Š๋Š”๋‹ค. ๋Œ€์‹ ์— repeat(์ •์ˆ˜ํ˜•) ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.
  2. b ์ค„๋งŒํผ ํ”„๋ฆฐํŠธํ•˜๊ธฐ. for ๋ฌธ ์ด์šฉ ๊ทธ๋ฆฌ๊ณ  println ํ•จ์ˆ˜ ์ด์šฉํ•ด์„œ ์ค„๋ฐ”๊ฟˆํ•ด์ฃผ๊ธฐ.

 

๐ŸŽ€ Answer

fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(' ').map(String::toInt)
    var String = "*".repeat(a)
    for (i in 0 until b) {
        println(String)
    }
}

 

๐ŸŽ Result

๐Ÿ† Comment

standard input output์€ ๋ฆฌํ„ด ๊ฐ’์„ ์ด์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค.

์ธํ’‹ํ•  ๋•Œ readLine()!!.split(" ").map(String::toInt) ์‚ฌ์šฉํ•ด์คŒ.

์ค„์„ ์ฝ์–ด์ฃผ๊ณ 

" "์ŠคํŽ˜์ด์Šค ๋งˆ๋‹ค ๋‚˜๋ˆ„์–ด์ฃผ๊ณ 

๊ฐ ๊ฐ’์„ ๋ฌธ์ž์—ด์—์„œ ์ •์ˆ˜ํ˜•์œผ๋กœ ๋ฐ”๊พธ์–ด์คŒ.