Question: Matrix problem

I have an Nx3 Matrix A and each row looks like [integer,integer,*]. Matrix A acts like a function of two variables in the sense that the ordered pairs that you get be selecting the first two entries of each row are all distinct.

I would like a slick way to convert A to a Matrix B for which B[i,j]=* where * is the third entry in the unique row of A that looks like [i,j,*]. We can insert 0 for "blanks."

For example, if


1 3 a
1 4 d
1 1 b
3 3 c
3 4 a
 then would like B to be
 b 0 a d
 0 0 0 0
 0 0 c a
 Notice, for example, B[1,3]=a, which corresponds to the first row of A. This is a toy example. In my application, N is going to be around 300.
I can't seem to hit on the right approach. Every time I try something, I go off on a wild chase and end up with nonsense.

Please Wait...