[R21A]选手排名
- 难度 普及−
- 时限 1s
- 空限 512m
- 模拟
数据规模:, 仅由小写字母组成且长度不超过 ,保证两位选手解题数量和罚时至少有一个不同。
思路
按题目给定的排名规则依次比较两位选手:
- 先比较解题数量 ,解题数量大的排名靠前;
- 解题数量相同时,再比较罚时 ,罚时小的排名靠前。
由于数据保证两位选手在 与 中至少有一项不同,所以无需处理完全并列的情况,直接用条件判断即可选出排名更高者。
复杂度
时间 ,空间 。
仓颉实现
import std.env.*
import std.convert.*
main(): Int64 {
let reader = getStdIn()
let line1 = reader.readln().getOrThrow().split(" ", removeEmpty: true)
let name1 = line1[0]
let x1 = Int64.parse(line1[1])
let y1 = Int64.parse(line1[2])
let line2 = reader.readln().getOrThrow().split(" ", removeEmpty: true)
let name2 = line2[0]
let x2 = Int64.parse(line2[1])
let y2 = Int64.parse(line2[2])
// 排名规则:解题数量多的靠前;相同时罚时少的靠前
var winner: String = name1
if (x1 > x2) {
winner = name1
} else if (x1 < x2) {
winner = name2
} else {
if (y1 < y2) {
winner = name1
} else {
winner = name2
}
}
println(winner)
return 0
}