-
Kotlin π¬ λ°±μ€ 13λ¨κ³ :: 2751 λ²2023. 7. 2. 17:41λ°μν
μ μ λ ¬νκΈ° 2
λ¬Έμ |
Nκ°μ μκ° μ£Όμ΄μ‘μ λ, μ΄λ₯Ό μ€λ¦μ°¨μμΌλ‘ μ λ ¬νλ νλ‘κ·Έλ¨μ μμ±νμμ€.
μ λ ₯ |
첫째 μ€μ μμ κ°μ N(1 ≤ N ≤ 1,000,000)μ΄ μ£Όμ΄μ§λ€. λμ§Έ μ€λΆν° Nκ°μ μ€μλ μκ° μ£Όμ΄μ§λ€. μ΄ μλ μ λκ°μ΄ 1,000,000λ³΄λ€ μκ±°λ κ°μ μ μμ΄λ€. μλ μ€λ³΅λμ§ μλλ€.
μΆλ ₯ |
첫째 μ€λΆν° Nκ°μ μ€μ μ€λ¦μ°¨μμΌλ‘ μ λ ¬ν κ²°κ³Όλ₯Ό ν μ€μ νλμ© μΆλ ₯νλ€.
νμ΄ |
sort() ν¨μλ₯Ό μ΄μ©ν΄ μ λ ¬ ν μΆλ ₯
λ΅μ |
import java.util.Scanner fun main() = with(Scanner(System.`in`)) { val N = nextInt() val score = IntArray(N){ nextInt() } score.sort() score.forEach { println("${it}") } }
μ΄μκ°μ΄ Scannerλ₯Ό μ΄μ©ν΄ μ λ ₯μ λ°μμ§λ§ μκ°μ΄κ³Ό λμλ€.
import java.io.BufferedReader import java.io.InputStreamReader import java.util.StringTokenizer fun main() { val br = BufferedReader(InputStreamReader(System.`in`)) val N = br.readLine().toInt() val score = IntArray(N) { br.readLine().toInt() } score.sort() val sb = StringBuilder() for (s in score) { sb.append("$s\n") } println(sb) }
Scanner λμ BufferedReaderλ₯Ό μ΄μ©ν΄ μ μΆλ ₯νλ λ°©μμΌλ‘ μ μ©νλ€.
...
κ·Έλ°λ° λ μκ°μ΄κ³Όκ° λ°μνμ¬ μμ νμ§λ§ λ μκ°μ΄κ³Ό,,,
fun main() { val N = readLine()!!.toInt() val score = IntArray(N) { readLine()!!.toInt() } score.sort() val result = score.joinToString("\n") println(result) }
μλ μ½λλ‘ μ±κ³΅
import java.io.BufferedReader import java.io.InputStreamReader import java.lang.StringBuilder fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { val N = Integer.parseInt(readLine()) val sb = StringBuilder() val score = ArrayList<Int>(N) val bw = System.out.bufferedWriter() repeat(N) { score.add(Integer.parseInt(readLine())) } score.sort() sb.append(score.joinToString("\n")) bw.write(sb.toString()) bw.close() }
λ°μν'π Algorithm > π λ°±μ€' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
Kotlin π¬ λ°±μ€ 13λ¨κ³ :: 1427 λ² (0) 2023.07.04 Kotlin π¬ λ°±μ€ 13λ¨κ³ :: 10989 λ² (0) 2023.07.03 Kotlin π¬ λ°±μ€ 13λ¨κ³ :: 25305 λ² (0) 2023.07.01 Kotlin π¬ λ°±μ€ 13λ¨κ³ :: 2587 λ² (0) 2023.06.28 Kotlin π¬ λ°±μ€ 13λ¨κ³ :: 2750 λ² (0) 2023.06.27