50064. Merge Sort

I'm a slow walker, but I never walk backwards.

Task Description

Given $N$ binary files and each file contains multiple four-byte integers in ascending order, write a program to read the files and print all integers in those files in ascending order. For example, If we are given three files $1.dat$, $2.dat$, and $3.dat$. The contents of the files are as follows (in decimal).

| 1.dat | 2.dat | 3.dat |
|-------|-------|-------|
|  5    |  2    |  19   |
|  14   |  23   |  55   |
|  27   |  36   |       |
|       |  40   |       |

We should output the integers in the following order.

2
5
14
19
23
27
36
40
55

Hint

You should first read one integer from all files, so you have $N$ integers. Then you repeat the following process. Print the smallest one among these $N$ integers. If that smallest integer is from file $F$, then replace the smallest integer with the next integer from file $F$. You repeat this process until you have read all integers from all files.

Input Format

There is one test case. The first line contains an integer $N$ indicating the number of binary files.
Each of the following $N$ lines contains a string $S$ indicating the name of a file.
$0 \lt N \lt 16.$
$0 \lt $ length of $S \lt 16.$

Output Format

Print all integers on separate lines.

Sample Input

Download: 1.dat, 2.dat, 3.dat

3
1.dat
2.dat
3.dat

Sample Output

2
5
14
19
23
27
36
40
55

Discussion