๐ Algorithm
-
Kotlin ๐ฌ ๋ฐฑ์ค 5๋จ๊ณ :: 2743 ๋ฒ2023. 4. 13. 21:55
๋จ์ด ๊ธธ์ด ์ฌ๊ธฐ ๋ฌธ์ | ์ํ๋ฒณ์ผ๋ก๋ง ์ด๋ฃจ์ด์ง ๋จ์ด๋ฅผ ์ ๋ ฅ๋ฐ์, ๊ทธ ๊ธธ์ด๋ฅผ ์ถ๋ ฅํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค. ์ ๋ ฅ | ์ฒซ์งธ ์ค์ ์์ด ์๋ฌธ์์ ๋๋ฌธ์๋ก๋ง ์ด๋ฃจ์ด์ง ๋จ์ด๊ฐ ์ฃผ์ด์ง๋ค. ๋จ์ด์ ๊ธธ์ด๋ ์ต๋ 100์ด๋ค. ์ถ๋ ฅ | ์ฒซ์งธ ์ค์ ์ ๋ ฅ์ผ๋ก ์ฃผ์ด์ง ๋จ์ด์ ๊ธธ์ด๋ฅผ ์ถ๋ ฅํ๋ค. ํ์ด | readLine()์ ์ด์ฉํด ์ ๋ ฅ์ ๋ฐ์ ์ถ๋ ฅ ๋ต์ | fun main() { val word = readLine()!!.toString() print("${word.length}") }
-
Kotlin ๐ฌ ๋ฐฑ์ค 5๋จ๊ณ :: 27866 ๋ฒ2023. 4. 12. 21:46
๋ฌธ์์ ๋ฌธ์์ด ๋ฌธ์ | ๋จ์ด S์ ์ ์ i๊ฐ ์ฃผ์ด์ก์ ๋, S์ i๋ฒ์งธ ๊ธ์๋ฅผ ์ถ๋ ฅํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค. ์ ๋ ฅ | ์ฒซ์งธ ์ค์ ์์ด ์๋ฌธ์์ ๋๋ฌธ์๋ก๋ง ์ด๋ฃจ์ด์ง ๋จ์ด S๊ฐ ์ฃผ์ด์ง๋ค. ๋จ์ด์ ๊ธธ์ด๋ ์ต๋ 1000์ด๋ค. ๋์งธ ์ค์ ์ ์ i๊ฐ ์ฃผ์ด์ง๋ค. (1≤i≤|S|) ์ถ๋ ฅ | S์ i๋ฒ์งธ ๊ธ์๋ฅผ ์ถ๋ ฅํ๋ค. ํ์ด | Scanner๋ฅผ ์ด์ฉํด ์ ๋ ฅ์ ๋ฐ์ ์ถ๋ ฅ ๋ต์ | import java.util.Scanner fun main() = with(Scanner(System.`in`)) { print("${next()[nextInt() - 1]}") }
-
Kotlin ๐ฌ ๋ฐฑ์ค 4๋จ๊ณ :: 1546 ๋ฒ2023. 4. 11. 21:39
ํ๊ท ๋ฌธ์ | ์ธ์ค์ด๋ ๊ธฐ๋ง๊ณ ์ฌ๋ฅผ ๋ง์ณค๋ค. ์ธ์ค์ด๋ ์ ์๋ฅผ ์กฐ์ํด์ ์ง์ ๊ฐ์ ธ๊ฐ๊ธฐ๋ก ํ๋ค. ์ผ๋จ ์ธ์ค์ด๋ ์๊ธฐ ์ ์ ์ค์ ์ต๋๊ฐ์ ๊ณจ๋๋ค. ์ด ๊ฐ์ M์ด๋ผ๊ณ ํ๋ค. ๊ทธ๋ฆฌ๊ณ ๋์ ๋ชจ๋ ์ ์๋ฅผ ์ ์/M*100์ผ๋ก ๊ณ ์ณค๋ค. ์๋ฅผ ๋ค์ด, ์ธ์ค์ด์ ์ต๊ณ ์ ์ด 70์ด๊ณ , ์ํ์ ์๊ฐ 50์ด์์ผ๋ฉด ์ํ์ ์๋ 50/70*100์ด ๋์ด 71.43์ ์ด ๋๋ค. ์ธ์ค์ด์ ์ฑ์ ์ ์์ ๋ฐฉ๋ฒ๋๋ก ์๋ก ๊ณ์ฐํ์ ๋, ์๋ก์ด ํ๊ท ์ ๊ตฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค. ์ ๋ ฅ | ์ฒซ์งธ ์ค์ ์ํ ๋ณธ ๊ณผ๋ชฉ์ ๊ฐ์ N์ด ์ฃผ์ด์ง๋ค. ์ด ๊ฐ์ 1000๋ณด๋ค ์๊ฑฐ๋ ๊ฐ๋ค. ๋์งธ ์ค์ ์ธ์ค์ด์ ํ์ฌ ์ฑ์ ์ด ์ฃผ์ด์ง๋ค. ์ด ๊ฐ์ 100๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ ์์ด ์๋ ์ ์์ด๊ณ , ์ ์ด๋ ํ๋์ ๊ฐ์ 0๋ณด๋ค ํฌ๋ค. ์ถ๋ ฅ | ์ฒซ์งธ ์ค์ ์๋ก์ด ํ๊ท ์ ์ถ๋ ฅํ๋ค. ์ค์ ์ ๋ต..
-
Kotlin ๐ฌ ๋ฐฑ์ค 4๋จ๊ณ :: 10811 ๋ฒ2023. 4. 10. 21:07
๋ฐ๊ตฌ๋ ๋ค์ง๊ธฐ ๋ฌธ์ | ๋ํ์ด๋ ๋ฐ๊ตฌ๋๋ฅผ ์ด N๊ฐ ๊ฐ์ง๊ณ ์๊ณ , ๊ฐ๊ฐ์ ๋ฐ๊ตฌ๋์๋ 1๋ฒ๋ถํฐ N๋ฒ๊น์ง ๋ฒํธ๊ฐ ์์๋๋ก ์ ํ์ ธ ์๋ค. ๋ฐ๊ตฌ๋๋ ์ผ๋ ฌ๋ก ๋์ฌ์ ธ ์๊ณ , ๊ฐ์ฅ ์ผ์ชฝ ๋ฐ๊ตฌ๋๋ฅผ 1๋ฒ์งธ ๋ฐ๊ตฌ๋, ๊ทธ ๋ค์ ๋ฐ๊ตฌ๋๋ฅผ 2๋ฒ์งธ ๋ฐ๊ตฌ๋, ..., ๊ฐ์ฅ ์ค๋ฅธ์ชฝ ๋ฐ๊ตฌ๋๋ฅผ N๋ฒ์งธ ๋ฐ๊ตฌ๋๋ผ๊ณ ๋ถ๋ฅธ๋ค. ๋ํ์ด๋ ์์ผ๋ก M๋ฒ ๋ฐ๊ตฌ๋์ ์์๋ฅผ ์ญ์์ผ๋ก ๋ง๋ค๋ ค๊ณ ํ๋ค. ๋ํ์ด๋ ํ ๋ฒ ์์๋ฅผ ์ญ์์ผ๋ก ๋ฐ๊ฟ ๋, ์์๋ฅผ ์ญ์์ผ๋ก ๋ง๋ค ๋ฒ์๋ฅผ ์ ํ๊ณ , ๊ทธ ๋ฒ์์ ๋ค์ด์๋ ๋ฐ๊ตฌ๋์ ์์๋ฅผ ์ญ์์ผ๋ก ๋ง๋ ๋ค. ๋ฐ๊ตฌ๋์ ์์๋ฅผ ์ด๋ป๊ฒ ๋ฐ๊ฟ์ง ์ฃผ์ด์ก์ ๋, M๋ฒ ๋ฐ๊ตฌ๋์ ์์๋ฅผ ์ญ์์ผ๋ก ๋ง๋ ๋ค์, ๋ฐ๊ตฌ๋์ ์ ํ์๋ ๋ฒํธ๋ฅผ ๊ฐ์ฅ ์ผ์ชฝ ๋ฐ๊ตฌ๋๋ถํฐ ์ถ๋ ฅํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค. ์ ๋ ฅ | ์ฒซ์งธ ์ค์ N (1 ≤ N ≤ 100)๊ณผ M (1 ≤..
-
Kotlin ๐ฌ ๋ฐฑ์ค 4๋จ๊ณ :: 3052 ๋ฒ2023. 4. 9. 16:46
๋๋จธ์ง ๋ฌธ์ | ๋ ์์ฐ์ A์ B๊ฐ ์์ ๋, A%B๋ A๋ฅผ B๋ก ๋๋ ๋๋จธ์ง ์ด๋ค. ์๋ฅผ ๋ค์ด, 7, 14, 27, 38์ 3์ผ๋ก ๋๋ ๋๋จธ์ง๋ 1, 2, 0, 2์ด๋ค. ์ 10๊ฐ๋ฅผ ์ ๋ ฅ๋ฐ์ ๋ค, ์ด๋ฅผ 42๋ก ๋๋ ๋๋จธ์ง๋ฅผ ๊ตฌํ๋ค. ๊ทธ ๋ค์ ์๋ก ๋ค๋ฅธ ๊ฐ์ด ๋ช ๊ฐ ์๋์ง ์ถ๋ ฅํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค. ์ ๋ ฅ | ์ฒซ์งธ ์ค๋ถํฐ ์ด๋ฒ์งธ ์ค ๊น์ง ์ซ์๊ฐ ํ ์ค์ ํ๋์ฉ ์ฃผ์ด์ง๋ค. ์ด ์ซ์๋ 1,000๋ณด๋ค ์๊ฑฐ๋ ๊ฐ๊ณ , ์์ด ์๋ ์ ์์ด๋ค. ์ถ๋ ฅ | ์ฒซ์งธ ์ค์, 42๋ก ๋๋์์ ๋, ์๋ก ๋ค๋ฅธ ๋๋จธ์ง๊ฐ ๋ช ๊ฐ ์๋์ง ์ถ๋ ฅํ๋ค. ํ์ด | 1. ๋๋จธ์ง๋ฅผ ๋ด๋ int array ์ ์ 2. ์ ๋ ฅ๊ฐ์ 42๋ก ๋๋ ๋๋จธ์ง๊ฐ int array์ ํด๋นํ๋ ๊ฐ์ด ์๋ ๊ฒฝ์ฐ array์ ์ ์ฅ ๋ต์ | import java.ut..
-
Kotlin ๐ฌ ๋ฐฑ์ค 4๋จ๊ณ :: 5597 ๋ฒ2023. 4. 8. 16:27
๊ณผ์ ์ ๋ด์ ๋ถ...? ๋ฌธ์ | X๋ํ M๊ต์๋์ ํ๋ก๊ทธ๋๋ฐ ์์ ์ ๋งก๊ณ ์๋ค. ๊ต์ค์ ํ์์ด 30๋ช ์ด ์๋๋ฐ, ํ์ ๋ช ๋ถ์ ๊ฐ ํ์๋ณ๋ก 1๋ฒ๋ถํฐ 30๋ฒ๊น์ง ์ถ์๋ฒํธ๊ฐ ๋ถ์ด ์๋ค. ๊ต์๋์ด ๋ด์ค ํน๋ณ๊ณผ์ ๋ฅผ 28๋ช ์ด ์ ์ถํ๋๋ฐ, ๊ทธ ์ค์์ ์ ์ถ ์ ํ ํ์ 2๋ช ์ ์ถ์๋ฒํธ๋ฅผ ๊ตฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค. ์ ๋ ฅ | ์ ๋ ฅ์ ์ด 28์ค๋ก ๊ฐ ์ ์ถ์(ํ์)์ ์ถ์๋ฒํธ n(1 ≤ n ≤ 30)๊ฐ ํ ์ค์ ํ๋์ฉ ์ฃผ์ด์ง๋ค. ์ถ์๋ฒํธ์ ์ค๋ณต์ ์๋ค. ์ถ๋ ฅ | ์ถ๋ ฅ์ 2์ค์ด๋ค. 1๋ฒ์งธ ์ค์ ์ ์ถํ์ง ์์ ํ์์ ์ถ์๋ฒํธ ์ค ๊ฐ์ฅ ์์ ๊ฒ์ ์ถ๋ ฅํ๊ณ , 2๋ฒ์งธ ์ค์์ ๊ทธ ๋ค์ ์ถ์๋ฒํธ๋ฅผ ์ถ๋ ฅํ๋ค. ํ์ด | 1 ๋ถํฐ 30๊น์ง ์๊ฐ ๋ด๊ฒจ์๋ array์์ ์ ๋ ฅ๋ฐ์ ์ ์ ๊ฑฐ IntArray๋ ํฌ๊ธฐ๊ฐ ๊ณ ์ ๋ ๋ฐฐ์ด์ด๋ฏ๋ก ์์ ์ ๊ฑฐ..
-
Kotlin ๐ฌ ๋ฐฑ์ค 4๋จ๊ณ :: 10813 ๋ฒ2023. 4. 7. 15:45
๊ณต ๋ฐ๊พธ๊ธฐ ๋ฌธ์ | ๋ํ์ด๋ ๋ฐ๊ตฌ๋๋ฅผ ์ด N๊ฐ ๊ฐ์ง๊ณ ์๊ณ , ๊ฐ๊ฐ์ ๋ฐ๊ตฌ๋์๋ 1๋ฒ๋ถํฐ N๋ฒ๊น์ง ๋ฒํธ๊ฐ ๋งค๊ฒจ์ ธ ์๋ค. ๋ฐ๊ตฌ๋์๋ ๊ณต์ด 1๊ฐ์ฉ ๋ค์ด์๊ณ , ์ฒ์์๋ ๋ฐ๊ตฌ๋์ ์ ํ์๋ ๋ฒํธ์ ๊ฐ์ ๋ฒํธ๊ฐ ์ ํ ๊ณต์ด ๋ค์ด์๋ค. ๋ํ์ด๋ ์์ผ๋ก M๋ฒ ๊ณต์ ๋ฐ๊พธ๋ ค๊ณ ํ๋ค. ๋ํ์ด๋ ๊ณต์ ๋ฐ๊ฟ ๋ฐ๊ตฌ๋ 2๊ฐ๋ฅผ ์ ํํ๊ณ , ๋ ๋ฐ๊ตฌ๋์ ๋ค์ด์๋ ๊ณต์ ์๋ก ๊ตํํ๋ค. ๊ณต์ ์ด๋ป๊ฒ ๋ฐ๊ฟ์ง๊ฐ ์ฃผ์ด์ก์ ๋, M๋ฒ ๊ณต์ ๋ฐ๊พผ ์ดํ์ ๊ฐ ๋ฐ๊ตฌ๋์ ์ด๋ค ๊ณต์ด ๋ค์ด์๋์ง ๊ตฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค. ์ ๋ ฅ | ์ฒซ์งธ ์ค์ N (1 ≤ N ≤ 100)๊ณผ M (1 ≤ M ≤ 100)์ด ์ฃผ์ด์ง๋ค. ๋์งธ ์ค๋ถํฐ M๊ฐ์ ์ค์ ๊ฑธ์ณ์ ๊ณต์ ๊ตํํ ๋ฐฉ๋ฒ์ด ์ฃผ์ด์ง๋ค. ๊ฐ ๋ฐฉ๋ฒ์ ๋ ์ ์ i j๋ก ์ด๋ฃจ์ด์ ธ ์์ผ๋ฉฐ, i๋ฒ ๋ฐ๊ตฌ๋์ j๋ฒ ๋ฐ๊ตฌ๋์ ๋ค์ด์๋ ..
-
Kotlin ๐ฌ ๋ฐฑ์ค 4๋จ๊ณ :: 10810 ๋ฒ2023. 4. 6. 15:27
๊ณต ๋ฃ๊ธฐ ๋ฌธ์ | ๋ํ์ด๋ ๋ฐ๊ตฌ๋๋ฅผ ์ด N๊ฐ ๊ฐ์ง๊ณ ์๊ณ , ๊ฐ๊ฐ์ ๋ฐ๊ตฌ๋์๋ 1๋ฒ๋ถํฐ N๋ฒ๊น์ง ๋ฒํธ๊ฐ ๋งค๊ฒจ์ ธ ์๋ค. ๋, 1๋ฒ๋ถํฐ N๋ฒ๊น์ง ๋ฒํธ๊ฐ ์ ํ์๋ ๊ณต์ ๋งค์ฐ ๋ง์ด ๊ฐ์ง๊ณ ์๋ค. ๊ฐ์ฅ ์ฒ์ ๋ฐ๊ตฌ๋์๋ ๊ณต์ด ๋ค์ด์์ง ์์ผ๋ฉฐ, ๋ฐ๊ตฌ๋์๋ ๊ณต์ 1๊ฐ๋ง ๋ฃ์ ์ ์๋ค. ๋ํ์ด๋ ์์ผ๋ก M๋ฒ ๊ณต์ ๋ฃ์ผ๋ ค๊ณ ํ๋ค. ๋ํ์ด๋ ํ ๋ฒ ๊ณต์ ๋ฃ์ ๋, ๊ณต์ ๋ฃ์ ๋ฐ๊ตฌ๋ ๋ฒ์๋ฅผ ์ ํ๊ณ , ์ ํ ๋ฐ๊ตฌ๋์ ๋ชจ๋ ๊ฐ์ ๋ฒํธ๊ฐ ์ ํ์๋ ๊ณต์ ๋ฃ๋๋ค. ๋ง์ฝ, ๋ฐ๊ตฌ๋์ ๊ณต์ด ์ด๋ฏธ ์๋ ๊ฒฝ์ฐ์๋ ๋ค์ด์๋ ๊ณต์ ๋นผ๊ณ , ์๋ก ๊ณต์ ๋ฃ๋๋ค. ๊ณต์ ๋ฃ์ ๋ฐ๊ตฌ๋๋ ์ฐ์๋์ด ์์ด์ผ ํ๋ค. ๊ณต์ ์ด๋ป๊ฒ ๋ฃ์์ง๊ฐ ์ฃผ์ด์ก์ ๋, M๋ฒ ๊ณต์ ๋ฃ์ ์ดํ์ ๊ฐ ๋ฐ๊ตฌ๋์ ์ด๋ค ๊ณต์ด ๋ค์ด ์๋์ง ๊ตฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค. ์ ๋ ฅ | ์ฒซ์งธ ์ค์ N (1..