백준 31925번 APC2shake! Kotlin

: ) YOUNG·2024년 11월 21일
1

알고리즘

목록 보기
417/422
post-thumbnail

백준 31925번 APC2shake! Kotlin

https://www.acmicpc.net/problem/31925

문제



생각하기


  • 문자열

  • 부르트포스 문제이다.



동작



결과


코드



import java.io.File
import java.util.StringTokenizer

// input
private var br = System.`in`.bufferedReader()

// variables
private var N = 0

private data class Student(
    val name: String, val rank: Int
) : Comparable<Student> {
    override fun compareTo(o: Student): Int {
        return rank - o.rank
    }
} // End of Student class

fun main() {
    val bw = System.out.bufferedWriter()

    input()

    bw.write(solve())
    bw.close()
} // End of main()

private fun solve(): String {
    val sb = StringBuilder()

    val list = ArrayList<Student>()
    repeat(N) {
        val st = StringTokenizer(br.readLine());

        val name = st.nextToken()
        val status = st.nextToken()
        val isWinner = st.nextToken()
        val rank = st.nextToken().toInt()
        val apcRank = st.nextToken().toInt()


        if (status == "jaehak" && isWinner == "notyet" && (rank == -1 || rank > 3)) {
            list.add(Student(name, apcRank))
        }
    }

    list.sort()
    val selectedStudents = list.take(10).map { it.name }.toMutableList()

    selectedStudents.sort()

    sb.append(selectedStudents.size).append('\n')
    selectedStudents.forEach {
        sb.append(it).append('\n')
    }

    return sb.toString()
} // End of solve()

private fun input() {
    N = br.readLine().toInt()
} // End of input()

0개의 댓글