#P5483. [JLOI2011] 小A的烦恼

[JLOI2011] 小A的烦恼

Description

Little AA is a PM (product market) at company BB. Company BB is paying more and more attention to analyzing product usage, and Little AA's job is to stare at piles of data all day and analyze them over and over again, endlessly. One operation that gives Little AA a big headache is copying data from multiple csvcsv files into the same excelexcel file.

One day, Little AA came to you with great expectations. As a senior programmer, she wants you to write a program to help her complete this simple, repetitive task. But that is troublesome: directly operating on excelexcel requires third-party libraries. It is better to write directly into a csvcsv file and let her manually convert it into an excelexcel file later. After internal communication and coordination, this plan was finally chosen.

csvcsv is a format supported by excelexcel, and its storage is very simple. It uses “,” to separate two adjacent columns. For example, the following three lines of data:

a,a,a
b,,b
,c,c

represent:

a
b b
c

Now, what Little AA wants to do is to copy each file into the same file from left to right. For example, file aa contains:

a1,b1,c1
a2,b2

and file bb contains:

a1,b1,c1,d1
a2,b2
a3,b3,c3
a4

Then the final result she wants is:

a b
a1 b1 c1 a1 b1 c1 d1
a2 b2 a2 b2
a3 b3 c3
a4

In a csvcsv file, this result is:

a,,,b,,,
a1,b1,c1,a1,b1,c1,d1
a2,b2,,a2,b2,,
,,,a3,b3,c3,
,,,a4,,,

The first line of the result above is the file name of each file. Each file name is aligned with the first column of its corresponding file. If the corresponding file has more than one column, the other columns are filled with empty cells.

The input csvcsv files guarantee that there is no “,” at the end of any line. That is, like the third column in the second line of file aa: if that cell is empty, then there is no “,” after b2.

Since the output csvcsv file is produced by a program, to simplify the program, if the end is empty, it will still explicitly output “,”, as shown in the result above.

The input guarantees that there is at least one non-empty row and one non-empty column.

In the output file, the first column of the next file must be immediately to the right of the last non-empty column of the previous file. The last file should only be output up to its last non-empty column.

Input Format

The first line contains an integer NN (1N1001 \leq N \leq 100), meaning there are NN files.

For each of the following NN data blocks, the first line contains an integer MM (1M1001 \leq M \leq 100) and a string SS (1length(S)1001 \leq length(S) \leq 100). MM is the number of rows in the file, and SS is the file name.

In each data block, the next MM lines each contain a string TT (1length(T)1001 \leq length(T) \leq 100). TT only contains lowercase letters, digits, and “,”.

Output Format

Output the result of merging the data from the NN files into one file.

2
2 a
a1,b1,c1
a2,b2
4 b
a1,b1,c1,d1
a2,b2
a3,b3,c3
a4
a,,,b,,,
a1,b1,c1,a1,b1,c1,d1
a2,b2,,a2,b2,,
,,,a3,b3,c3,
,,,a4,,,

Hint

Translated by ChatGPT 5