// Maksims_Gutovs_PD_31_03
using System;
using System.Linq;

class HelloWorld
{
    static void Main()
    {
        TabulasGalva();
        int[,] tabula = TabulasDati("Maksims", "Gutovs");
        Tabula(tabula, 1);
        Console.WriteLine("Apgriezta tabula\n");
        TabulasGalva();
        tabula = TabulasMaina(tabula);
        Tabula(tabula, 0);
    }

    static void TabulasLinija(int ss, int rs)
    {
        Console.Write("*");
        for (int j = 0; j < rs; j++)
        {
            for (int i = 0; i < ss; i++)
            {
                Console.Write("-");
            }
            Console.Write("*");
        }
        Console.WriteLine();
    }

    static void TabulasRinda(int[] rd, int max, int min, int sum)
    {
        for (int i = 0; i < rd.Length; i++)
        {
            Console.Write($"|\t{rd[i]}\t");
        }
        if (max == 0)
        {
            Console.Write("|\tmax\t");
            Console.Write("|\tmin\t");
            Console.Write("|\tsum\t|");
        }
        else
            Console.Write("");
        Console.WriteLine();
    }

    static int[,] TabulasDati(string vards, string uzvards)
    {
        Random rnd = new Random();
        int[,] mas1 = new int[uzvards.Length, vards.Length];

        int num = 0;
        for (int i = 0; i < uzvards.Length; i++)
        {
            for (int j = 0; j < vards.Length; j++)
            {
                num = rnd.Next((vards.Length), (vards.Length + uzvards.Length + 1));
                mas1[i, j] = num;
            }
        }
        return mas1;
    }

    static string TabulasGalva(string x = ("Maksims"))
    {
        Console.WriteLine(x);
        TabulasLinija(15, 10);
        int[] rd = { 1, 2, 3, 4, 5, 6, 7 };
        TabulasRinda(rd, 0, 0, 0);
        return x;
    }

    static void Tabula(int[,] x, int y)
    {
        TabulasLinija(15, 10);
        int[] mas1 = new int[x.GetLength(1)];
        for (int i = 0; i < x.GetLength(0); i++)
        {
            for (int j = 0; j < x.GetLength(1); j++)
            {
                Console.Write($"|\t{x[i, j]}\t");
                mas1[j] = x[i, j];
            }
            if (y == 0)
                Console.Write("|\t\t");
            Console.Write($"|\t{mas1.Max()}\t");
            Console.Write($"|\t{mas1.Min()}\t");
            Console.WriteLine($"|\t{mas1.Sum()}\t|");
        }
        TabulasLinija(15, 10);
    }

    static int[,] TabulasMaina(int[,] tabula)
    {
        int rows = tabula.GetLength(0);
        int colums = tabula.GetLength(1);
        int[,] tabmain = new int[colums, rows];

        for (int i = 0; i < rows; i++)
        {
            for (int j = 0; j < colums; j++)
            {
                tabmain[j, i] = tabula[i, j];
            }
        }
        return tabmain;
    }
}
