using System;
class Matrix<T> {
private int rows;
private int cols;
private T[,] matrix;
public Matrix() {
rows = cols = 0;
matrix = null;
}
public Matrix(int m, int n) {
rows = m;
cols = n;
matrix = new T[m, n];
}
public T this[int i, int j] {
get {
if (i < rows && j < cols)
return matrix[i, j];
else
throw new ArgumentOutOfRangeException();
}
set {
if (i < rows && j < cols)
matrix[i, j] = value;
else
throw new ArgumentOutOfRangeException();
}
}
public int Rows {
get { return rows; }
}
public int Cols {
get { return cols; }
}
}
public class Test
{
public static void Main()
{
Matrix<int> myMatrix=new Matrix<int>(3,2);
myMatrix[0,0]=1;
myMatrix[0,1]=2;
myMatrix[1,0]=3;
myMatrix[1,1]=4;
myMatrix[2,0]=5;
myMatrix[2,1]=6;
for(int i=0; i<3; i++)
{
for(int j=0; j<2; j++)
Console.Write(myMatrix[i,j] + "\t");
Console.WriteLine();
}
}
}
dXNpbmcgU3lzdGVtOwpjbGFzcyBNYXRyaXg8VD4geyAKICAgICAgICBwcml2YXRlIGludCByb3dzOyAKICAgICAgICBwcml2YXRlIGludCBjb2xzOyAKICAgICAgICBwcml2YXRlIFRbLF0gbWF0cml4OyAKIAogICAgICAgIHB1YmxpYyBNYXRyaXgoKSB7IAogICAgICAgICAgICByb3dzID0gY29scyA9IDA7IAogICAgICAgICAgICBtYXRyaXggPSBudWxsOyAKICAgICAgICB9IAogCiAgICAgICAgcHVibGljIE1hdHJpeChpbnQgbSwgaW50IG4pIHsgCiAgICAgICAgICAgIHJvd3MgPSBtOyAKICAgICAgICAgICAgY29scyA9IG47IAogICAgICAgICAgICBtYXRyaXggPSBuZXcgVFttLCBuXTsgCiAgICAgICAgfSAKIAogICAgICAgIHB1YmxpYyBUIHRoaXNbaW50IGksIGludCBqXSB7IAogICAgICAgICAgICBnZXQgeyAKICAgICAgICAgICAgICAgIGlmIChpIDwgcm93cyAmJiBqIDwgY29scykgCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIG1hdHJpeFtpLCBqXTsgCiAgICAgICAgICAgICAgICBlbHNlIAogICAgICAgICAgICAgICAgICAgIHRocm93IG5ldyBBcmd1bWVudE91dE9mUmFuZ2VFeGNlcHRpb24oKTsgCiAgICAgICAgICAgIH0gCiAgICAgICAgICAgIHNldCB7IAogICAgICAgICAgICAgICAgaWYgKGkgPCByb3dzICYmIGogPCBjb2xzKSAKICAgICAgICAgICAgICAgICAgICBtYXRyaXhbaSwgal0gPSB2YWx1ZTsgCiAgICAgICAgICAgICAgICBlbHNlIAogICAgICAgICAgICAgICAgICAgIHRocm93IG5ldyBBcmd1bWVudE91dE9mUmFuZ2VFeGNlcHRpb24oKTsgCiAgICAgICAgICAgIH0gCiAgICAgICAgfSAKIAogICAgICAgIHB1YmxpYyBpbnQgUm93cyB7IAogICAgICAgICAgICBnZXQgeyByZXR1cm4gcm93czsgfSAKICAgICAgICB9IAogCiAgICAgICAgcHVibGljIGludCBDb2xzIHsgCiAgICAgICAgICAgIGdldCB7IHJldHVybiBjb2xzOyB9IAogICAgICAgIH0gCn0KCnB1YmxpYyBjbGFzcyBUZXN0CnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKCXsKCQlNYXRyaXg8aW50PiBteU1hdHJpeD1uZXcgTWF0cml4PGludD4oMywyKTsKCQlteU1hdHJpeFswLDBdPTE7CQoJCW15TWF0cml4WzAsMV09MjsKCQlteU1hdHJpeFsxLDBdPTM7CgkJbXlNYXRyaXhbMSwxXT00OwoJCW15TWF0cml4WzIsMF09NTsKCQlteU1hdHJpeFsyLDFdPTY7CgoJCWZvcihpbnQgaT0wOyBpPDM7IGkrKykKCSAgICB7CgkgICAgCWZvcihpbnQgaj0wOyBqPDI7IGorKykKCQkJCUNvbnNvbGUuV3JpdGUobXlNYXRyaXhbaSxqXSArICJcdCIpOwoJCQlDb25zb2xlLldyaXRlTGluZSgpOwoJICAgIH0KICAgIH0KfQo=