/*
    Veidoja: Emīlija Anna Bukus
    Grupa: 110
    Prakiskais darbs 5
    Izmantotais Compiler: www.onlinegdb.com
*/

using System;
using System.Linq;
using System.Collections.Generic;

class HelloWorld
{
    static void Main()
    {
        Console.WriteLine("\nPirmais uzd. -- 2D masivs");
        int[,] viens = 
        {
            { 1, 2, 3, 4 },
            { 10, 20, 30, 40 },
            { 100, 200, 300, 400 }
        };
        
        for (int i = 0; i < viens.GetLength(0); i++) 
        {  
            for (int j = 0; j < viens.GetLength(1); j++) 
            {  
            Console.Write(viens[i, j] + " ");  
            }
        Console.WriteLine();
        }
        
        Console.WriteLine("\nOtrais uzd. -- Robotais masivs,");
        
        int[][] divi = 
        {
            new int[] { 1, 2 },
            new int[] { 10, 20, 30 },
            new int[] { 100 }
        };
        
        for (int i = 0; i < divi.Length; i++)
        {
            for (int j = 0; j < divi[i].Length; j++)
            {
                Console.Write(divi[i][j] + " ");
            }
            Console.WriteLine();
        }
        
        Console.WriteLine("\nTresais uzd. -- 2D masiva rindu summa");
        
        int[,] tris =
        {
            { 1, 2, 3, 4, 5 },
            { 10, 20, 30, 40, 50 },
            { 100, 200, 300, 400, 500 },
            { 1000, 2000, 3000, 4000, 5000 }
        };
        
        for (int i = 0; i < tris.GetLength(0); i++)
        {
            int summa = 0;
            for (int j = 0; j < tris.GetLength(1); j++)
            {
                summa += tris[i, j];
            }
            Console.WriteLine($"Rindas summa: " + summa);
        }
        
        Console.WriteLine("\nCeturtais uzd -- robotais masīva elementa meklēšana");
        
        int[][] cetri =
        {
            new int[] { 1, 2, 3, 4, 5 },
            new int[] { 6, 7, 8 },
            new int[] { 9, 10, 11, 12, 13, 14, 15, 16, 17 }
        };
        
        Console.Write("Ievadi skaitli, kuru vēlies meklēt: ");
        string izvele = Console.ReadLine();
        
        if (int.TryParse(izvele, out int meklejamais))
        {
            bool atrasts = false;
            
            for (int i = 0; i < cetri.Length; i++)
            {
                for (int j = 0; j < cetri[i].Length; j++)
                {
                    if (cetri[i][j] == meklejamais)
                    {
                        Console.WriteLine($"Skaitlis {meklejamais} atrodas rindā {i}, kolonnā {j}.");
                        atrasts = true;
                    }
                }
            }
            
            if (!atrasts)
            {
                Console.WriteLine($"Skaitlis {meklejamais} neatrodas dotajā masīvā.");
            }
        }
        
        Console.WriteLine("\nPiektais uzd -- Robota masiva rindu sakartosana");
        
        int[][] pieci =
        {
            new int[] { 2, 6, 8, 3, 5, 1 },
            new int[] { 0, 14, 63, 854, 83, 74, 23, 12, 11, 19},
            new int[] { 73, 634, 897, 235, 578, 367, 2456, 34, 84, 115, 16, 112 }
        };
        
        for (int i = 0; i < pieci.Length; i++)
        {
            Array.Sort(pieci[i]);
            
            Console.Write($"Rinda {i + 1}: ");
            Console.WriteLine(string.Join(", ", pieci[i]));
        }
        Console.WriteLine("Viss masīvs sakārtots.");
        
        /*
        6.	2D Masīvs – Matricas Transponēšana:
•	Uzdevums: Izveidojiet NxM (piemēram, 3x5) 2D masīvu. Izveidojiet jaunu 2D masīvu MxN izmērā,
    kas ir sākotnējā masīva transponētā matrica (rindas kļūst par kolonnām un kolonnas par rindām).
    Izdrukājiet abas matricas.
•	Koncepts: Vairākdimensiju masīvu izmēru apmaiņa, elementu pārvietošana ($A[i, j] \rightarrow B[j, i]$).

https://stackoverflow.com/questions/18368611/how-do-i-transpose-a-multi-dimensional-array
https://learn.microsoft.com/en-us/answers/questions/736595/c-transpose-a-2d-matrix-looking-for-the-best-way
https://codesignal.com/learn/courses/multidimensional-arrays-and-their-traversal-in-csharp/lessons/transposing-matrices-in-csharp


        Console.WriteLine("\nSestais uzd -- 2D masiva matricas Transponēšana");
        
        int[,] sesi =
        {
            { 1, 2, 3, 4, 5 },
            { 6, 7, 8, 9, 10 },
            { 11, 12, 13, 14, 15 }
        };
*/
    }
}