This statement is better seen in the pdf file. A matrix is said to be sparse when almost all its values are zero. Write a program that computes the sum of sparse matrices.
Input
Input is a sequence of cases. Each case consits on the description of two sparse matrix. An sparse matrix is described by a non negative integer number n followed by a sequence of n integer triples. Triple i j v with v ≠ 0 defines v as the value of the matrix at row i column j. We assume that i and j are non negative and that matrix values at non listed positions are zero. For instance, the first output matrix in the sample output below is:
⎛ ⎜ ⎜ ⎜ ⎝ |
| ⎞ ⎟ ⎟ ⎟ ⎠ |
Output
For each case, write the sum of the two input matrices as a sequence of triples. Write only those triples that show a non zero value of the sum matrix. Write one triple at each line. Triples must appear ordered by rows. Triples of the same row must appear ordered by columns. After each case, print a line with ten dashes.
Input
3 1 1 1 0 0 5 2 3 1 5 3 3 1 0 0 -1 2 2 5 1 1 -1 2 3 1 1 0 0 5 1 0 0 -5 3 2 1 -1 0 0 1 1 2 1 2 0 0 -2 2 1 1
Output
0 0 4 2 2 5 2 3 2 3 3 1 ---------- ---------- 0 0 -1 1 2 1 ----------