题解 | #合并表记录#
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
import Foundation while let line = readLine() { var count = Int(line)! var map = [Int: Int]() while count > 0 { let row = readLine() let array = row!.split(separator: " ") let key = Int(array[0])! var value = Int(array[1])! if let v = map[key] { value += v } map[key] = value count -= 1 } let keys = map.keys.sorted(by: { $0 < $1 }) for key in keys { print("\(key) \(map[key]!)") } }