P5483 [JLOI2011] Little A's Trouble

Description

Little $A$ is a PM (product market) at company $B$. Company $B$ is paying more and more attention to analyzing product usage, and Little $A$'s job is to stare at piles of data all day and analyze them over and over again, endlessly. One operation that gives Little $A$ a big headache is copying data from multiple $csv$ files into the same $excel$ file. One day, Little $A$ 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 $excel$ requires third-party libraries. It is better to write directly into a $csv$ file and let her manually convert it into an $excel$ file later. After internal communication and coordination, this plan was finally chosen. $csv$ is a format supported by $excel$, 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 | a | a | | ---------- | :----------: | :----------: | | b | | b | | | c | c | Now, what Little $A$ wants to do is to copy each file into the same file from left to right. For example, file $a$ contains: ``` a1,b1,c1 a2,b2 ``` and file $b$ 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 $csv$ 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 $csv$ files guarantee that there is no “,” at the end of any line. That is, like the third column in the second line of file $a$: if that cell is empty, then there is no “,” after `b2`. Since the output $csv$ 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 $N$ ($1 \leq N \leq 100$), meaning there are $N$ files. For each of the following $N$ data blocks, the first line contains an integer $M$ ($1 \leq M \leq 100$) and a string $S$ ($1 \leq length(S) \leq 100$). $M$ is the number of rows in the file, and $S$ is the file name. In each data block, the next $M$ lines each contain a string $T$ ($1 \leq length(T) \leq 100$). $T$ only contains lowercase letters, digits, and “,”.

Output Format

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

Explanation/Hint

Translated by ChatGPT 5