distributed-computing/tasks/melnikov-ky/lab_5/Lab5/Controller.cs

78 lines
1.9 KiB
C#
Raw Normal View History

2023-12-18 16:46:40 +04:00
using System.Drawing;
namespace Lab5
{
public class Controller
{
public string PrintResultMatrix(int[,] result)
{
string resultString = "";
for (int i = 0; i < result.GetLength(0); i++)
{
for (int j = 0; j < result.GetLength(1); j++)
{
resultString += result[i, j];
if (j != result.GetLength(1) - 1)
{
resultString += " ";
}
}
resultString += Environment.NewLine;
}
return resultString;
}
public int[,] GetMatrixFromTextbox(string inputText)
{
string[] lines = inputText.Split(Environment.NewLine);
int numRows = lines.Length;
int numCol = lines[0].Split(' ').Length;
int[,] matrix = new int[numRows, numCol];
for (int i = 0; i < numRows; i++)
{
string[] elements = lines[i].Split(' ');
for (int j = 0; j < numCol; j++)
{
matrix[i, j] = int.Parse(elements[j]);
}
}
return matrix;
}
public string GetTextFromFile(string filePath)
{
string text = "";
using (StreamReader sr = new StreamReader(filePath))
{
text = sr.ReadToEnd();
}
return text;
}
public int[,] GenerateNewMatrix(int count)
{
Random random = new Random();
int[,] matrix = new int[count, count];
for (int i = 0; i < count; i++)
{
for (int j = 0; j < count; j++)
{
matrix[i, j] = random.Next(1, 26);
}
}
return matrix;
}
}
}