#C12328. Merge Dictionaries
Merge Dictionaries
Merge Dictionaries
You are given several dictionaries. Each dictionary contains several key-value pairs. If the same key appears in multiple dictionaries, you are to sum their corresponding integer values. Your task is to merge all the dictionaries into one and output the result with keys sorted in lexicographical order.
Input Format: The first line contains an integer n, the number of dictionaries. For each dictionary, the first line contains an integer m indicating the number of key-value pairs, followed by m lines each containing a string and an integer separated by a space.
Output Format: Output the merged dictionary where each line contains a key and its total sum, with keys printed in increasing lexicographical order. Each key-value pair should be printed on a separate line, separated by a space.
inputFormat
The input begins with an integer n
denoting the number of dictionaries. For each dictionary, the first integer m
indicates the number of key-value pairs in that dictionary. This is followed by m
lines, each containing a key (a string without spaces) and a value (an integer), separated by a space.
outputFormat
Print the merged dictionary’s key-value pairs sorted by key in ascending lexicographical order. Each line should contain a key and its corresponding sum separated by a space.
## sample2
2
a 100
b 200
2
c 300
d 400
a 100
b 200
c 300
d 400
</p>