PAT 乙级(Basic Level)kotlin版 1024-1026

//1024 偷懒.jpg

import java.io.BufferedReader
import java.io.InputStreamReader
import java.math.BigDecimal

fun main(args: Array) {
    val kin = BufferedReader(InputStreamReader(System.`in`))
    val bigDecimal = BigDecimal(kin.readLine())
    println(bigDecimal.toPlainString())
}
//1025
//测试点5超时
import java.io.*

fun main(args: Array) {

//    val cin = StreamTokenizer(BufferedReader(InputStreamReader(System.`in`)))
    val out = PrintWriter(OutputStreamWriter(System.out))
    val kin = BufferedReader(InputStreamReader(System.`in`))
//    cin.nextToken()
//    var s = cin.sval.split(" ")
    var s = kin.readLine().split(" ")
    val start = s[0]
    var next = start

    var count = s[1].toInt()
    val reverse = s[2].toInt()

    val nodes = ArrayList(count)
    val result = ArrayList(count)

    //非空检查
    if (count == 0)
        return

    //保存
    for (i in 0 until count) {
        s = kin.readLine().split(" ")
        nodes.add(Node(s[0], s[1].toInt(), s[2]))
    }

    //有序
    while (true) {
        val node = find(next, nodes)!!
        result.add(node)
        next = node.next
        if (node.next == "-1")
            break
    }
    count = result.size
//    result.forEach { out.println(it) }

//    nodes.clear()

    //翻转
    if (reverse == 0 || reverse == 1 || count == 1) {
        result.forEach { out.println(it) }
        out.flush()
        return
    }

    var startPos = 0
    while (startPos + reverse <= count) {
        for (i in 0 until reverse) {
            val tmpNode = result[startPos + i]
            nodes[startPos + reverse - i - 1] = tmpNode
        }
        startPos+=reverse
    }

    for (i in startPos until count){
        nodes[i] = result[i]
    }

    for (i in 0 until count){
        val node = nodes[i]
        if (i!=count-1)
            out.println("${node.address} ${node.data} ${nodes[i + 1].address}")
        else
            out.print("${node.address} ${node.data} ${-1}")
    }
    out.flush()
}

fun find(addr: String, nodes: List): Node? {
    nodes.forEach {
        if (it.address == addr)
            return it
    }
    return null
}

class Node(val address: String, val data: Int, var next: String) {
    var nextNode: Node? = null
    var preNode: Node? = null

    override fun toString(): String {
        return "$address $data $next"
    }
}
//1026

import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.io.PrintWriter
import java.text.NumberFormat

fun main(args: Array) {
    val kin = BufferedReader(InputStreamReader(System.`in`))
    val out = PrintWriter(OutputStreamWriter(System.out))
    val nf = NumberFormat.getInstance()
    nf.minimumIntegerDigits = 2

    val s = kin.readLine().split(" ")
    val start = s[0].toInt()
    val end = s[1].toInt()
    val duration = end - start + 50

    val time = duration/100
    //out.printf("${time/(3600)}:${time%(3600)/60}:${time%60}","%02d%02d%02d")
    out.printf("${nf.format(time/3600)}:${nf.format(time%(3600)/60)}:${nf.format(time%60)}")
    out.flush()

}

你可能感兴趣的:(PAT 乙级(Basic Level)kotlin版 1024-1026)