美文网首页
PAT 乙级(Basic Level)kotlin版 1032-

PAT 乙级(Basic Level)kotlin版 1032-

作者: qmr777 | 来源:发表于2020-11-08 01:16 被阅读0次
    哪家强?

    可以用StreamTokenizer实现更快的输入(但是仍然会超时)
    调用nextToken()读取一个数据(string或double),会自动以空格和回车作为分割,读一个调一次
    调用st.sval获得刚刚读取的String,st.nval获得Double

    //挖掘机 https://pintia.cn/problem-sets/994805260223102976/problems/994805289432236032
    //1032测试点4超时
    import java.io.*
    
    fun main(args: Array<String>) {
        //println("蓝翔")
        val st = StreamTokenizer(BufferedReader(InputStreamReader(System.`in`)))
        val kout = PrintWriter(OutputStreamWriter(System.out))
        st.
        val count = st.nval.toInt()
        var maxScore = 0
        var maxScoreSchool = 0
    
        val list = IntArray(count + 1)
        for (i in 1..count) {
            st.nextToken()
            val school = st.nval.toInt()
            st.nextToken()
            val score = st.nval.toInt()
            list[school] += score
        }
    
        for (i in list.indices) {
            if (list[i] > maxScore) {
                maxScoreSchool = i
                maxScore = list[i]
            }
        }
    
        kout.println("$maxScoreSchool $maxScore")
        kout.flush()
    }
    

    相关文章

      网友评论

          本文标题:PAT 乙级(Basic Level)kotlin版 1032-

          本文链接:https://www.haomeiwen.com/subject/rdycbktx.html