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 double Rows {
get { return rows; }
}
public double Cols {
get { return cols; }
}
}
public class Test
{
public static void Main()
{
Matrix<double> myMatrix=new Matrix<double>(3,2);
myMatrix[0,0]=1.5;
myMatrix[0,1]=16.0;
myMatrix[1,0]=18.0;
myMatrix[1,1]=3.6;
myMatrix[2,0]=7.1;
myMatrix[2,1]=2.9;
for(int i=0; i<3; i++)
{
for(int j=0; j<2; j++)
Console.Write(myMatrix[i,j] + "\t");
Console.WriteLine();
}
}
}
dXNpbmcgU3lzdGVtOwpjbGFzcyBNYXRyaXg8VD4geyAKICAgICAgICBwcml2YXRlIGludCByb3dzOyAKICAgICAgICBwcml2YXRlIGludCBjb2xzOyAKICAgICAgICBwcml2YXRlIFRbLF0gbWF0cml4OyAKIAogICAgICAgIHB1YmxpYyBNYXRyaXgoKSB7IAogICAgICAgICAgICByb3dzID0gY29scyA9IDA7IAogICAgICAgICAgICBtYXRyaXggPSBudWxsOyAKICAgICAgICB9IAogCiAgICAgICAgcHVibGljIE1hdHJpeChpbnQgbSwgaW50IG4pIHsgCiAgICAgICAgICAgIHJvd3MgPSBtOyAKICAgICAgICAgICAgY29scyA9IG47IAogICAgICAgICAgICBtYXRyaXggPSBuZXcgVFttLCBuXTsgCiAgICAgICAgfSAKIAogICAgICAgIHB1YmxpYyBUIHRoaXNbaW50IGksIGludCBqXSB7IAogICAgICAgICAgICBnZXQgeyAKICAgICAgICAgICAgICAgIGlmIChpIDwgcm93cyAmJiBqIDwgY29scykgCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIG1hdHJpeFtpLCBqXTsgCiAgICAgICAgICAgICAgICBlbHNlIAogICAgICAgICAgICAgICAgICAgIHRocm93IG5ldyBBcmd1bWVudE91dE9mUmFuZ2VFeGNlcHRpb24oKTsgCiAgICAgICAgICAgIH0gCiAgICAgICAgICAgIHNldCB7IAogICAgICAgICAgICAgICAgaWYgKGkgPCByb3dzICYmIGogPCBjb2xzKSAKICAgICAgICAgICAgICAgICAgICBtYXRyaXhbaSwgal0gPSB2YWx1ZTsgCiAgICAgICAgICAgICAgICBlbHNlIAogICAgICAgICAgICAgICAgICAgIHRocm93IG5ldyBBcmd1bWVudE91dE9mUmFuZ2VFeGNlcHRpb24oKTsgCiAgICAgICAgICAgIH0gCiAgICAgICAgfSAKIAogICAgICAgIHB1YmxpYyBkb3VibGUgUm93cyB7IAogICAgICAgICAgICBnZXQgeyByZXR1cm4gcm93czsgfSAKICAgICAgICB9IAogCiAgICAgICAgcHVibGljIGRvdWJsZSBDb2xzIHsgCiAgICAgICAgICAgIGdldCB7IHJldHVybiBjb2xzOyB9IAogICAgICAgIH0gCn0KCnB1YmxpYyBjbGFzcyBUZXN0CnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKCXsKCQlNYXRyaXg8ZG91YmxlPiBteU1hdHJpeD1uZXcgTWF0cml4PGRvdWJsZT4oMywyKTsKCQlteU1hdHJpeFswLDBdPTEuNTsJCgkJbXlNYXRyaXhbMCwxXT0xNi4wOwoJCW15TWF0cml4WzEsMF09MTguMDsKCQlteU1hdHJpeFsxLDFdPTMuNjsKCQlteU1hdHJpeFsyLDBdPTcuMTsKCQlteU1hdHJpeFsyLDFdPTIuOTsKCgkJZm9yKGludCBpPTA7IGk8MzsgaSsrKQoJICAgIHsKCSAgICAJZm9yKGludCBqPTA7IGo8MjsgaisrKQoJCQkJQ29uc29sZS5Xcml0ZShteU1hdHJpeFtpLGpdICsgIlx0Iik7CgkJCUNvbnNvbGUuV3JpdGVMaW5lKCk7CgkgICAgfQogICAgfQp9Cg==