题解 | #合并表记录#
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
import java.util.Scanner fun main(args: Array<String>) { val read = Scanner(System.`in`) val res = read.nextLine().toInt() val map = HashMap<Int, Long>(res) for (i in 1..res) { val line = read.nextLine() val pair = line.split(' ').map { it.toInt() } map[pair[0]] = pair[1] + (map[pair[0]]?:0L) } map.forEach { it.apply { println("$key $value") } } }