/*
    Veidoja: Artūrs Peškovs
    Grupa: 110
    Praktiskais darbs: 5
    Izmantotais Compiler: Visual Studio Code  Version: 1.106.2
*/


using System;

public class PR5
{
    public static void uzd_1()
    {
        int[,] d2 = {
            {1,2,3,4},
            {5,6,7,8},
            {9,10,11,12}
        };
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                Console.Write($"{d2[i, j]} ");
            }
            Console.WriteLine();
        }
    }
    public static void uzd_2()
    {
        int[][] d3 = { 
            new int[]{2,3}, 
            new int[]{4,5,6}, 
            new int[]{9} 
        }; 

        Console.WriteLine(); 
        for(int i = 0; i < 3; i++) 
        { 
            foreach(int g in d3[i]) 
            { 
                Console.Write($"{g} "); 
            } 
            Console.WriteLine(); 
        } 
    }
    public static void uzd_3()
    {
        Console.WriteLine(); 

        int[,] d4 = { 
            {1,2,3,4,5}, 
            {6,7,8,9,10}, 
            {11,12,13,14,15}, 
            {16,17,18,19,20} 
        }; 

        int sum = 0; 
        for (int i = 0; i < 4; i++) 
        { 
            Console.Write($"Rinda {i}: "); 
            for (int j = 0; j < 5; j++) 
            { 
                sum += d4[i, j]; 
            } 
            Console.WriteLine($"{sum} "); 
        }
    }
    public static void uzd_4()
    {
        Console.WriteLine(); 
        int[][] d5 = { 
            new int[]{1,2,3,4,5}, 
            new int[]{6,7,8,9,10}, 
            new int[]{11,12,13,14,15} 
        }; 

        Console.WriteLine("Ievadi skaitli"); 
        int skaitlis = Convert.ToInt32(Console.ReadLine()); 

        for(int i = 0; i < 3; i++) 
        { 
            for(int j = 0; j < 5; j++) 
            { 
                if(d5[i][j]==skaitlis) 
                { 
                    Console.WriteLine($"Rinda {i} un kolonna {j} "); 
                    Console.WriteLine($"{skaitlis} "); 
                } 
            } 
        } 
    }
    public static void uzd_5()
    {
        Console.WriteLine(); 
        int[][] d6 = { 
            new int[]{15,3,1,2}, 
            new int[]{6,9,4,2}, 
            new int[]{32,12,3,54} 
        }; 

        Console.WriteLine("Bija");

        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                Console.Write($"{d6[i][j]} ");
            }
            Console.WriteLine();
        }
        
        for (int i = 0; i < 3; i++)
        {
            for (int j = 4 - 1; j > 0; j--)
            {
                for (int k = 0; k < j; k++)
                {
                    if (d6[i][k] > d6[i][k + 1])
                    {
                        int temp = d6[i][k];

                        d6[i][k] = d6[i][k + 1];

                        d6[i][k + 1] = temp;
                    }
                }
            }
        } 
        
        Console.WriteLine(); 
        Console.WriteLine("Tagat"); 

        for (int i = 0; i < 3; i++) 
        { 
            for (int j = 0; j < 4; j++) 
            { 
                Console.Write($"{d6[i][j]} "); 
            } 
            Console.WriteLine(); 
        } 
    }
    public static void uzd_6()
    {
        int[,] matrix = {
            { 2, 3, 1 , 2, 5},
            { 5, 6, 3 , 6, 7},
            { 8, 0, 4 , 9, 2}
        };

        Console.WriteLine("-------------------------Bija---------------------------");
        Console.Write("\t"); //atstarpe
        for (int i = 0; i < matrix.GetLength(1); i++) 
        {
            Console.Write($"Kolonna {i}:\t");
        }
        Console.WriteLine();


        for (int i = 0; i < matrix.GetLength(0); i++)
        {
            Console.Write($"Rinda {i}: \t");
            for (int j = 0; j < matrix.GetLength(1); j++)
            {
                Console.Write(matrix[i, j] + " \t");
                Console.Write(" \t");
            }
            Console.WriteLine();
        }
        
        Console.WriteLine("-------------------------Tagat---------------------------");
        Console.Write("\t"); //atstarpe
        for (int i = 0; i < matrix.GetLength(0); i++) 
        {
            Console.Write($"Rinda {i}:\t");
        }
        Console.WriteLine();


        for(int i = 0; i< matrix.GetLength(1); i++)
        {
            Console.Write($"Kolonna {i}: \t");
            for (int j = 0; j < matrix.GetLength(0); j++) //Index was outside the bounds of the array kad GetLength(1)???
            {

                //int perem = matrix[j, i]; // kaut kas nav ta, pazud 3,1,3 cipari 3x3
                //Console.Write(perem + " \t");
                Console.Write(matrix[j,i] + " \t");
                //Console.Write($"kolonna {j} | rinda {i} ");
                //Console.Write($"-------------{perem}------------ ");
                //matrix[i,j] = perem; // kautkas nav ta, pazud 3,1,3 cipari 3x3
                //Console.Write(" \t");
                //Console.Write($"-------------{perem}------------ \t");
                //Console.Write(matrix[i,j] + " \t");
                Console.Write(" \t");
            }
            Console.WriteLine();
        }
    }
    public static void Main(string[] args)
    {
        uzd_1();
        uzd_2();
        uzd_3();
        uzd_4();
        uzd_5();
        uzd_6();
    }
}