题解 | #合并表记录#
合并表记录
http://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
package main
import (
"fmt"
"sort"
)
func main() {
var n int
fmt.Scan(&n)
m := make(map[int]int)
var key []int
for i := 0; i < n; i++ {
var a, b int
fmt.Scan(&a)
fmt.Scan(&b)
m[a] += b
}
for k := range m {
key = append(key, k)
}
sort.Ints(key)
for _, v := range key {
fmt.Println(v, m[v])
}
}