/*https://onlinenotebook.net/jElvdcqnpbvQofn
    Veidoja: Artūrs Peškovs
    Grupa: 110
    Praktiskais darbs: 7
    Izmantotais Compiler: Visual Studio Code  Version: 1.106.2
*/

using System;
using System.Collections;
public class PR7
{
    // 1. uzd
    public static List<double> Ievadiet_Izdevumus(List<double> saraksts)
    {
        bool parbaude = true;
        while (parbaude == true)
        {
            Console.WriteLine("Ievadi summu"); 
            string? lietot = Console.ReadLine();
            //double lietotaja_summa = Convert.ToDouble(Console.ReadLine());
            bool flag = double.TryParse(lietot, out double num); // parbauda vai sanak no mainiga "lietot" double vertiba

            if (flag== true)
            {
                saraksts.Add(num);
            }
            
            else
            {
                Console.WriteLine("Saraksts");
                foreach(double s in saraksts)
                {
                    Console.WriteLine(s);
                }
                parbaude = false;
            }
        }
        return saraksts;
    }
    public static List<double> Filtret_Izdevumus(List<double> izejasDati, double slieksnis)
    {
        List<double> filtretais_saraksts = new List<double>();
        Console.WriteLine();
        Console.WriteLine("Filtretais");
        foreach(double s in izejasDati)
        {
            if(s < slieksnis)
            {
                continue;
            }
            filtretais_saraksts.Add(s);
            Console.WriteLine(s);
        }
        return filtretais_saraksts;
    }
    public static double Aprekinat_Mainibu(List<double> dati)
    {
        double min = dati[0]; // saraksta pirmais elements
        double max = dati[0]; // saraksta pirmais elements
        foreach(double k in dati)
        {
            if(k <min)
            {
                min = Math.Min(min,k);
            }
            if(k > max)
            {
                max = Math.Max(max,k);
            }
            //Console.WriteLine(k);
        }
        Console.WriteLine($"minimalais {min} | maksimalais {max}");
        double diapozons = Math.Abs(max - min);;
        return diapozons;
    }
    //2. uzd
    public static string Atklat_Preci(string[,] masivs, string kods)
    {
        bool parbaude = true;
        for(int i = 0; i < masivs.GetLength(0); i++)
        {
            for(int j = 0; j < masivs.GetLength(1); j++)
            {
                if(masivs[i, j] == kods)
                {
                    //Console.WriteLine($"eja {i} plaukts {j}");
                    kods = $"eja {i} plaukts {j}";
                    parbaude = false;
                    break;
                }
                //masivs[i,j] = "0";
                //Console.Write($"{masivs[i,j]} ");
            }
            if(parbaude == false)
            {
                break;
            }
            //Console.WriteLine();
        }
        if(parbaude)
        {
            kods = "nav tada koda preces";
        }
        return kods;
    }
    public static int Aprekinat_Neaizpilditas(string[,] masivs2,int tuks)
    {
        for(int i = 0; i < masivs2.GetLength(0); i++)
        {
            for(int j = 0; j < masivs2.GetLength(1); j++)
            {
                if(masivs2[i,j] == null)
                {
                    tuks++;
                }
            }    
        }
        return tuks;
    }
    //3. uzd
    public static double Aprekinat_Plaknes_Attalumu(double x1,double y1,double x2,double y2)
    {
        double pirmais_x = Math.Pow(x2-x1,2);
        double pirmais_y = Math.Pow(y2-y1,2);
        double attalums = Math.Sqrt(pirmais_x+pirmais_y);
        return attalums;
    }
    public static double Konvertet_Radianos(double gradi)
    {
        double pi = Math.PI;
        double radians = gradi * (pi/180);
        return radians;
    }
    public static void Main(string[] args)
    {
        //1. Uzd
        List<double> saraksts = new List<double>();
        
        List<double> kas = Ievadiet_Izdevumus(saraksts);
        double slieksnis = -10;
        List<double> filtretais = Filtret_Izdevumus(kas,slieksnis);

        double diapozons = Aprekinat_Mainibu(filtretais);
        Console.WriteLine($"Diapozons {diapozons}");

        //2. Uzd
        int eja = 4;
        int plaukti = 5;
        string[,] noliktava = new string[eja,plaukti]; // 4 rindas, 5 kolonnas

        noliktava[3, 2] = "Abols";

        Console.WriteLine("Ievadi preces kodu, piemeram: Abols ");
        string? kods = Console.ReadLine();
        string rez = Atklat_Preci(noliktava,kods);
        Console.WriteLine(rez);

        int viens = 0;
        int cik = Aprekinat_Neaizpilditas(noliktava,viens);
        Console.WriteLine($"vietas tuksas {cik}");

        //3.uzd
        Console.WriteLine("Ievadi 1. punkta x koordinates"); //x1
        double x1 = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine("Ievadi 1. punkta y koordinates");//y1
        double y1 = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine("Ievadi 2. punkta x koordinates");//x2
        double x2 = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine("Ievadi 2. punkta y koordinates");//y2
        double y2 = Convert.ToDouble(Console.ReadLine());

        double attalums = Aprekinat_Plaknes_Attalumu(x1,y1,x2,y2);
        Console.WriteLine(attalums);

        Console.WriteLine("Ievadi lenki grados"); //x1
        double gradi = Convert.ToDouble(Console.ReadLine());

        double radian = Konvertet_Radianos(gradi);
        Console.WriteLine(radian);
    }
}