/*
Veidoja: Fedosova Elizaveta
Grupa: 110
Praktiskais darbs 5
Izmantotais Compiler: www.onlinegdb.com
*/

using System;
class HelloWorld {
public static void Masivs() {
int[,] masivs = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12}
};

Console.WriteLine("2D masīvs:");
for (int r = 0; r < masivs.GetLength(0); r++){
int izv = 0;
for (int k = 0; k < masivs.GetLength(1); k++){
izv += masivs[r,k];
Console.WriteLine(izv);
}
Console.WriteLine();
}
Console.WriteLine();
}

public static void Robotais() {
string[][] robotais = {
new string[] {"apple", "ābols"},
new string[] {"horse", "zirgs", "grāmata"},
new string[] {"book"}
};

Console.WriteLine("Robotais masīvs:");
for (int r = 0; r < robotais.Length; r++){
for (int e = 0; e < robotais[r].Length; e++){ //nebūs ERR IndexOutOfRange
Console.WriteLine(robotais[r][e]);
}
Console.WriteLine();
}
Console.WriteLine();
}

public static void Summa() {
int[,] summa = {
{1, 0, 2, 3, 4},
{3, 4, 1, 7, 9},
{5, 3, 6, 3, 8},
{8, 4, 9, 7, 9}
};

Console.WriteLine("Masīvs:");
for (int r = 0; r < summa.GetLength(0); r++)
{
for (int k = 0; k < summa.GetLength(1); k++)
{
Console.Write(summa[r, k]);
}
Console.WriteLine();
}

Console.WriteLine("Rindu summas:");
for (int r = 0; r < summa.GetLength(0); r++)
{
int sum = 0;
for (int k = 0; k < summa.GetLength(1); k++)
{
sum += summa[r, k];
}
Console.WriteLine(sum);
Console.WriteLine();
}
Console.WriteLine();
}

public static void Meklesana() {
int[][] meklesana = {
new int[]{1, 2},
new int[]{3, 4, 5},
new int[]{6}
};
Console.WriteLine("Ievadiet veselo skaitli!");
int ievade = int.Parse(Console.ReadLine());
bool atrasts = false;
for (int r = 0; r < meklesana.Length; r++){
for (int e = 0; e < meklesana[r].Length; e++){
if (meklesana[r][e] == ievade){
atrasts = true;
Console.WriteLine($"[{r}][{e}]");
}
}
Console.WriteLine();
}
if (!atrasts) {
Console.WriteLine("Skaitlis neatrasts!");
}
Console.WriteLine();
}

public static void Sakartosana() {
int[][] sakartosana = {
new int[] {14, 62},
new int[] {43, 19, 87},
new int[] {665, 34, 2}
};
for (int r = 0; r < sakartosana.Length; r++){
Array.Sort(sakartosana[r]); //nevar Array.Sort(sakartosana), jo ir robotais masivs (katru rindu atsevišķi)!
}

for (int r = 0; r < sakartosana.Length; r++){
for (int e = 0; e < sakartosana[r].Length; e++){
int aug = 0;
aug += sakartosana[r][e];
Console.WriteLine(aug);
}
Console.WriteLine();
}
Console.WriteLine();
}

public static void MatrTransp() {
int[,] transpon = {
{1, 0, 2, 3, 4, 6},
{3, 4, 2, 7, 9, 3},
{5, 3, 6, 3, 8, 1}
};

int rindas = transpon.GetLength(0);
int kolonnas = transpon.GetLength(1);

int[,] transponeta = new int[kolonnas, rindas];

Console.WriteLine("Matrica:");

for (int n = 0; n < rindas; n++){
for (int m = 0; m < kolonnas; m++){
transponeta[m, n] = transpon[n, m];
Console.WriteLine(transpon[n, m]);
}
Console.WriteLine();
}

Console.WriteLine("Transponēta matrica:");
for (int n = 0; n < kolonnas; n++){
for (int m = 0; m < rindas; m++){
Console.WriteLine(transponeta[n, m]);
}
Console.WriteLine();
}
}

static void Main() {
Masivs();
Robotais();
Summa();
Meklesana();
Sakartosana();
MatrTransp();
}
}