Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static void Main()
- {
- }
- }
- class MatrixMultiply
- {
- public int[,] Do(int[,] left, int[,] right)
- {
- if (CheckOnCorrect(left, right))
- throw new IndexOutOfRangeException();
- int aRows = left.GetLength(0); int aCols = left.GetLength(1);
- int bRows = right.GetLength(0); int bCols = right.GetLength(1);
- int[,] result = new int[left.GetLength(0),right.GetLength(1)];
- for (int i = 0; i < aRows; ++i) // каждая строка A
- for (int j = 0; j < bCols; ++j) // каждый столбец B
- for (int k = 0; k < aCols; ++k)
- result[i,j] += left[i,k] * right[k,j];
- return result;
- }
- public bool CheckOnCorrect(int[,] left, int[,] right)
- {
- if ((left.GetLength(1) == right.GetLength(0)))
- return true;
- else
- return false;
- }
- }
- class MatrixSum
- {
- public int[,] Do(int[,] left, int[,] right)
- {
- if (CheckOnCorrect(left, right))
- throw new IndexOutOfRangeException();
- int[,] result = new int[left.GetLength(0),right.GetLength(1)];
- for (int i = 0; i < left.GetLength(0); ++i)
- for (int j = 0; j < left.GetLength(1); ++j)
- result[i,j] = left[i,j] + right[i,j];
- return result;
- }
- public bool CheckOnCorrect(int[,] left, int[,] right)
- {
- if ((left.GetLength(0) == right.GetLength(0)) && (left.GetLength(1) == right.GetLength(1)))
- return true;
- else
- return false;
- }
- }
- class IO
- {
- public int[,] ReadMatrix(string path)
- {
- string[] text = File.ReadAllLines(path);
- int[,] result = new int[text.Length, text[0].Split(' ').Length];
- string[] bufer = new string[1];
- for (int i = 0; i < text.Length; i++)
- {
- bufer = text[i].Split(' ');
- for (int j = 0; j < bufer.Length; j++)
- {
- result[i,j] = int.Parse(bufer[j]);
- }
- }
- return result;
- }
- public int ReadInt(string path)
- {
- string number = File.ReadAllText(path);
- int cons = int.Parse(number);
- return cons;
- }
- public void WriteData(string path, string data)
- {
- File.AppendAllText(path, data);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement