๐ Algorithm
-
Kotlin ๐ฌ ๋ฐฑ์ค 6๋จ๊ณ :: 4344 ๋ฒ2023. 4. 29. 15:25
ํ๊ท ์ ๋๊ฒ ์ง ๋ฌธ์ | ๋ํ์ ์๋ด๊ธฐ๋ค์ 90%๋ ์์ ์ด ๋ฐ์์ ํ๊ท ์ ๋๋๋ค๊ณ ์๊ฐํ๋ค. ๋น์ ์ ๊ทธ๋ค์๊ฒ ์ฌํ ์ง์ค์ ์๋ ค์ค์ผ ํ๋ค. ์ ๋ ฅ | ์ฒซ์งธ ์ค์๋ ํ ์คํธ ์ผ์ด์ค์ ๊ฐ์ C๊ฐ ์ฃผ์ด์ง๋ค. ๋์งธ ์ค๋ถํฐ ๊ฐ ํ ์คํธ ์ผ์ด์ค๋ง๋ค ํ์์ ์ N(1 ≤ N ≤ 1000, N์ ์ ์)์ด ์ฒซ ์๋ก ์ฃผ์ด์ง๊ณ , ์ด์ด์ N๋ช ์ ์ ์๊ฐ ์ฃผ์ด์ง๋ค. ์ ์๋ 0๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ๊ณ , 100๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ ์ ์์ด๋ค. ์ถ๋ ฅ | ๊ฐ ์ผ์ด์ค๋ง๋ค ํ ์ค์ฉ ํ๊ท ์ ๋๋ ํ์๋ค์ ๋น์จ์ ๋ฐ์ฌ๋ฆผํ์ฌ ์์์ ์ ์งธ ์๋ฆฌ๊น์ง ์ถ๋ ฅํ๋ค. ํ์ด | ํ์๋ค์ ์ ์๋ฅผ ์ ์ฅํ array์ ํ๊ท ์ ๊ตฌํ ๋ค, ํ๊ท ๋ณด๋ค ๋์ ์ ์์ count()๋ฅผ ๊ตฌํ๋ค. ํด๋น count()์ ํ์ ์, ์ฆ ์ด์ ์ ์ ์๋ฅผ ์ ์ฅํ array์ size ๋๋ N์ ์ด์ฉํด ํ๊ท ์..
-
Kotlin ๐ฌ ๋ฐฑ์ค 6๋จ๊ณ :: 1157 ๋ฒ2023. 4. 28. 00:24
๋จ์ด ๊ณต๋ถ ๋ฌธ์ | ์ํ๋ฒณ ๋์๋ฌธ์๋ก ๋ ๋จ์ด๊ฐ ์ฃผ์ด์ง๋ฉด, ์ด ๋จ์ด์์ ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉ๋ ์ํ๋ฒณ์ด ๋ฌด์์ธ์ง ์์๋ด๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค. ๋จ, ๋๋ฌธ์์ ์๋ฌธ์๋ฅผ ๊ตฌ๋ถํ์ง ์๋๋ค. ์ ๋ ฅ | ์ฒซ์งธ ์ค์ ์ํ๋ฒณ ๋์๋ฌธ์๋ก ์ด๋ฃจ์ด์ง ๋จ์ด๊ฐ ์ฃผ์ด์ง๋ค. ์ฃผ์ด์ง๋ ๋จ์ด์ ๊ธธ์ด๋ 1,000,000์ ๋์ง ์๋๋ค. ์ถ๋ ฅ | ์ฒซ์งธ ์ค์ ์ด ๋จ์ด์์ ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉ๋ ์ํ๋ฒณ์ ๋๋ฌธ์๋ก ์ถ๋ ฅํ๋ค. ๋จ, ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉ๋ ์ํ๋ฒณ์ด ์ฌ๋ฌ ๊ฐ ์กด์ฌํ๋ ๊ฒฝ์ฐ์๋ ?๋ฅผ ์ถ๋ ฅํ๋ค. ํ์ด | mutableMap์ ๋จ์ด์ ๊ฐ character๋ฅผ key ๊ฐ์ผ๋ก ๋ฃ๊ณ value๋ฅผ ๊ธฐ๋ณธ 1๋ก ์ค์ ํด์ค๋ค. ๋์ผํ key ๊ฐ์ด ์์ผ๋ฉด value์ +1์ ๋ํด์ฃผ๋ฉด์ ์ค๋ณต๋ character์ ๊ฐ์๋ฅผ ์ผ๋ค. ๋ชจ๋ character๋ฅผ ์ฝ์ด์ค๋ฉด ์ต์ข ์ ์ผ..
-
Kotlin ๐ฌ ๋ฐฑ์ค 6๋จ๊ณ :: 10988 ๋ฒ2023. 4. 27. 00:51
ํฐ๋ฆฐ๋๋กฌ์ธ์ง ํ์ธํ๊ธฐ ๋ฌธ์ | ์ํ๋ฒณ ์๋ฌธ์๋ก๋ง ์ด๋ฃจ์ด์ง ๋จ์ด๊ฐ ์ฃผ์ด์ง๋ค. ์ด๋, ์ด ๋จ์ด๊ฐ ํฐ๋ฆฐ๋๋กฌ์ธ์ง ์๋์ง ํ์ธํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค. ํฐ๋ฆฐ๋๋กฌ์ด๋ ์์ผ๋ก ์ฝ์ ๋์ ๊ฑฐ๊พธ๋ก ์ฝ์ ๋ ๋๊ฐ์ ๋จ์ด๋ฅผ ๋งํ๋ค. level, noon์ ํฐ๋ฆฐ๋๋กฌ์ด๊ณ , baekjoon, online, judge๋ ํฐ๋ฆฐ๋๋กฌ์ด ์๋๋ค. ์ ๋ ฅ | ์ฒซ์งธ ์ค์ ๋จ์ด๊ฐ ์ฃผ์ด์ง๋ค. ๋จ์ด์ ๊ธธ์ด๋ 1๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ๊ณ , 100๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ผ๋ฉฐ, ์ํ๋ฒณ ์๋ฌธ์๋ก๋ง ์ด๋ฃจ์ด์ ธ ์๋ค. ์ถ๋ ฅ | ์ฒซ์งธ ์ค์ ํฐ๋ฆฐ๋๋กฌ์ด๋ฉด 1, ์๋๋ฉด 0์ ์ถ๋ ฅํ๋ค. ํ์ด | reversed() ํจ์ ์ฌ์ฉ ๋ต์ | fun main() { val word = readLine()!!.toString() if (word == word.reversed()) { print(..
-
Kotlin ๐ฌ ๋ฐฑ์ค 6๋จ๊ณ :: 10812 ๋ฒ2023. 4. 26. 00:45
๋ฐ๊ตฌ๋ ์์ ๋ฐ๊พธ๊ธฐ ๋ฌธ์ | ๋ํ์ด๋ ๋ฐ๊ตฌ๋๋ฅผ ์ด N๊ฐ ๊ฐ์ง๊ณ ์๊ณ , ๊ฐ๊ฐ์ ๋ฐ๊ตฌ๋์๋ 1๋ฒ๋ถํฐ N๋ฒ๊น์ง ๋ฒํธ๊ฐ ์์๋๋ก ์ ํ์ ธ ์๋ค. ๋ฐ๊ตฌ๋๋ ์ผ๋ ฌ๋ก ๋์ฌ์ ธ ์๊ณ , ๊ฐ์ฅ ์ผ์ชฝ ๋ฐ๊ตฌ๋๋ฅผ 1๋ฒ์งธ ๋ฐ๊ตฌ๋, ๊ทธ ๋ค์ ๋ฐ๊ตฌ๋๋ฅผ 2๋ฒ์งธ ๋ฐ๊ตฌ๋, ..., ๊ฐ์ฅ ์ค๋ฅธ์ชฝ ๋ฐ๊ตฌ๋๋ฅผ N๋ฒ์งธ ๋ฐ๊ตฌ๋๋ผ๊ณ ๋ถ๋ฅธ๋ค. ๋ํ์ด๋ ์์ผ๋ก M๋ฒ ๋ฐ๊ตฌ๋์ ์์๋ฅผ ํ์ ์ํค๋ ค๊ณ ๋ง๋ค๋ ค๊ณ ํ๋ค. ๋ํ์ด๋ ๋ฐ๊ตฌ๋์ ์์๋ฅผ ํ์ ์ํฌ ๋, ์์๋ฅผ ํ์ ์ํฌ ๋ฒ์๋ฅผ ์ ํ๊ณ , ๊ทธ ๋ฒ์ ์์์ ๊ธฐ์ค์ด ๋ ๋ฐ๊ตฌ๋๋ฅผ ์ ํํ๋ค. ๋ํ์ด๊ฐ ์ ํํ ๋ฐ๊ตฌ๋์ ๋ฒ์๊ฐ begin, end์ด๊ณ , ๊ธฐ์ค์ด ๋๋ ๋ฐ๊ตฌ๋๋ฅผ mid๋ผ๊ณ ํ์ ๋, begin, begin+1, ..., mid-1, mid, mid+1, ..., end-1, end ์์๋ก ๋์ด์๋ ๋ฐ๊ตฌ๋์ ์์๋ฅผ m..
-
Kotlin ๐ฌ ๋ฐฑ์ค 6๋จ๊ณ :: 2444 ๋ฒ2023. 4. 25. 20:56
๋ณ์ฐ๊ธฐ - 7 ๋ฌธ์ | ์์ ๋ฅผ ๋ณด๊ณ ๊ท์น์ ์ ์ถํ ๋ค์ ๋ณ์ ์ฐ์ด ๋ณด์ธ์. ์ ๋ ฅ | ์ฒซ์งธ ์ค์ N(1 ≤ N ≤ 100)์ด ์ฃผ์ด์ง๋ค. ์ถ๋ ฅ | ์ฒซ์งธ ์ค๋ถํฐ 2×N-1๋ฒ์งธ ์ค๊น์ง ์ฐจ๋ก๋๋ก ๋ณ์ ์ถ๋ ฅํ๋ค. ํ์ด | readLine()์ ์ด์ฉํด ์ ๋ ฅ์ ๋ฐ์ ์ถ๋ ฅ ๋ต์ | fun main() { val N = readLine()!!.toInt() for (i in 1 until N) { for (j in 1 until N - i + 1) { print(" ") } for (j in 1 until 2 * i) { print("*") } println() } for (i in N downTo 1) { for (j in 1 until N - i + 1) { print(" ") } for (j in 1 until 2 ..
-
Kotlin ๐ฌ ๋ฐฑ์ค 6๋จ๊ณ :: 3003 ๋ฒ2023. 4. 24. 20:32
ํน, ํธ, ๋ฃฉ, ๋น์, ๋์ดํธ, ํฐ ๋ฌธ์ | ๋ํ์ด๋ ์ค๋๋ ์ฐฝ๊ณ ๋ฅผ ๋ค์ง๋ค๊ฐ ๋ก์ ์ฒด์คํ๊ณผ ํผ์ค๋ฅผ ๋ฐ๊ฒฌํ๋ค. ์ฒด์คํ์ ๋จผ์ง๋ฅผ ํธ์ด๋ด๊ณ ๊ฑธ๋ ๋ก ๋ฆ์ผ๋ ๊ทธ๋ญ์ ๋ญ ์ธ๋งํ ์ฒด์คํ์ด ๋์๋ค. ํ์ง๋ง, ๊ฒ์ ์ ํผ์ค๋ ๋ชจ๋ ์์์ผ๋, ํฐ์ ํผ์ค๋ ๊ฐ์๊ฐ ์ฌ๋ฐ๋ฅด์ง ์์๋ค. ์ฒด์ค๋ ์ด 16๊ฐ์ ํผ์ค๋ฅผ ์ฌ์ฉํ๋ฉฐ, ํน 1๊ฐ, ํธ 1๊ฐ, ๋ฃฉ 2๊ฐ, ๋น์ 2๊ฐ, ๋์ดํธ 2๊ฐ, ํฐ 8๊ฐ๋ก ๊ตฌ์ฑ๋์ด ์๋ค. ๋ํ์ด๊ฐ ๋ฐ๊ฒฌํ ํฐ์ ํผ์ค์ ๊ฐ์๊ฐ ์ฃผ์ด์ก์ ๋, ๋ช ๊ฐ๋ฅผ ๋ํ๊ฑฐ๋ ๋นผ์ผ ์ฌ๋ฐ๋ฅธ ์ธํธ๊ฐ ๋๋์ง ๊ตฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค. ์ ๋ ฅ | ์ฒซ์งธ ์ค์ ๋ํ์ด๊ฐ ์ฐพ์ ํฐ์ ํน, ํธ, ๋ฃฉ, ๋น์, ๋์ดํธ, ํฐ์ ๊ฐ์๊ฐ ์ฃผ์ด์ง๋ค. ์ด ๊ฐ์ 0๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ๊ณ 10๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ ์ ์์ด๋ค. ์ถ๋ ฅ | ์ฒซ์งธ ์ค์ ์ ๋ ฅ์์ ์ฃผ์ด์ง ์์๋๋ก ๋ช ..
-
Kotlin ๐ฌ ๋ฐฑ์ค 6๋จ๊ณ :: 25083 ๋ฒ2023. 4. 23. 15:01
์์น ๋ฌธ์ | ์๋ ์์ ์ ๊ฐ์ด ์์น์ ์ถ๋ ฅํ์์ค. ์ ๋ ฅ | ์ ๋ ฅ์ ์๋ค. ์ถ๋ ฅ | ์์น์ ์ถ๋ ฅํ๋ค. ํ์ด | print() ํจ์๋ฅผ ์ด์ฉํ ์ถ๋ ฅ ๋ต์ | fun main() { println(""" ,r'"7 r`-_ ,' ,/ \. ". L_r' `~\/ | |""") }
-
Kotlin ๐ฌ ๋ฐฑ์ค 5๋จ๊ณ :: 11718 ๋ฒ2023. 4. 22. 14:57
๊ทธ๋๋ก ์ถ๋ ฅํ๊ธฐ ๋ฌธ์ | ์ ๋ ฅ ๋ฐ์ ๋๋ก ์ถ๋ ฅํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค. ์ ๋ ฅ | ์ ๋ ฅ์ด ์ฃผ์ด์ง๋ค. ์ ๋ ฅ์ ์ต๋ 100์ค๋ก ์ด๋ฃจ์ด์ ธ ์๊ณ , ์ํ๋ฒณ ์๋ฌธ์, ๋๋ฌธ์, ๊ณต๋ฐฑ, ์ซ์๋ก๋ง ์ด๋ฃจ์ด์ ธ ์๋ค. ๊ฐ ์ค์ 100๊ธ์๋ฅผ ๋์ง ์์ผ๋ฉฐ, ๋น ์ค์ ์ฃผ์ด์ง์ง ์๋๋ค. ๋, ๊ฐ ์ค์ ๊ณต๋ฐฑ์ผ๋ก ์์ํ์ง ์๊ณ , ๊ณต๋ฐฑ์ผ๋ก ๋๋์ง ์๋๋ค. ์ถ๋ ฅ | ์ ๋ ฅ๋ฐ์ ๊ทธ๋๋ก ์ถ๋ ฅํ๋ค. ํ์ด | 1) scanner์ hasNext() ๋ฉ์๋๋ฅผ ์ด์ฉํด ๋ค์์ ์ ๋ ฅ์ด ์กด์ฌํ๋์ง ํ์ธ ํ ์ถ๋ ฅ [172ms] 2) readLine์ ์ด์ฉํด ๋ค์์ ์ ๋ ฅ์ด ์กด์ฌํ๋์ง ํ์ธ ํ ์ถ๋ ฅ [156ms] ๋ต์ | import java.util.Scanner fun main() = with(Scanner(System.`in`)) { while (hasNe..