/*
Veidoja: Gustavs Skripa
Grupa: 110
Praktiskais darbs 7
izmantotais compiler: https://www.programiz.com
*/


using System;
using System.Collections.Generic;

class IzdevumuPrograma
{
    public static void Run()
    {
        var visi = IevadietIzdevumus();

        Console.Write("Ievadiet slieksni: ");
        double sl = double.Parse(Console.ReadLine());

        var lielie = Filtret(visi, sl);
        double diapazons = Mainiba(lielie);

        Console.WriteLine("Diapazons: " + diapazons);
    }

    static List<double> IevadietIzdevumus()
    {
        List<double> saraksts = new List<double>();
        Console.WriteLine("Ievadiet izdevumus (gals lai beigtu):");

        while (true)
        {
            string r = Console.ReadLine();
            if (r == "" || r == "gals") break;

            if (double.TryParse(r, out double s))
                saraksts.Add(s);
            else
                Console.WriteLine("Nederiga ievade");
        }

        return saraksts;
    }

    static List<double> Filtret(List<double> dati, double slieksnis)
    {
        List<double> jauns = new List<double>();
        foreach (double x in dati)
            if (x >= slieksnis) jauns.Add(x);
        return jauns;
    }

    static double Mainiba(List<double> dati)
    {
        if (dati.Count == 0) return 0;

        double min = dati[0];
        double max = dati[0];

        foreach (double x in dati)
        {
            if (x < min) min = x;
            if (x > max) max = x;
        }

        return max - min;
    }
}

class NoliktavaPrograma
{
    public static void Run()
    {
        string[,] nol = new string[4, 5]
        {
            { "A1", "A2", "", "A4", "A5" },
            { "B1", null, "B3", "B4", "B5" },
            { "C1", "C2", "C3", "", "C5" },
            { "D1", "D2", "D3", "D4", "D5" }
        };

        Console.Write("Ievadiet preces kodu: ");
        string k = Console.ReadLine();

        string atr = Atrast(nol, k);
        Console.WriteLine(atr);

        int t = Tuksi(nol);
        Console.WriteLine("Tuksie plaukti: " + t);
    }

    static string Atrast(string[,] m, string kods)
    {
        for (int e = 0; e < m.GetLength(0); e++)
            for (int p = 0; p < m.GetLength(1); p++)
                if (m[e, p] == kods)
                    return "Atrast Eja " + (e + 1) + ", Plaukts " + (p + 1);

        return "Nav atrasts";
    }

    static int Tuksi(string[,] m)
    {
        int s = 0;
        for (int e = 0; e < m.GetLength(0); e++)
            for (int p = 0; p < m.GetLength(1); p++)
                if (string.IsNullOrEmpty(m[e, p])) s++;
        return s;
    }
}

class AttalumaPrograma
{
    public static void Run()
    {
        Console.WriteLine("Ievadiet X1:");
        double x1 = double.Parse(Console.ReadLine());

        Console.WriteLine("Ievadiet Y1:");
        double y1 = double.Parse(Console.ReadLine());

        Console.WriteLine("Ievadiet X2:");
        double x2 = double.Parse(Console.ReadLine());

        Console.WriteLine("Ievadiet Y2:");
        double y2 = double.Parse(Console.ReadLine());

        double att = Attalums(x1, y1, x2, y2);
        Console.WriteLine("Attalums: " + att);

        Console.WriteLine("Ievadiet lenki grados:");
        double g = double.Parse(Console.ReadLine());

        double r = Radiani(g);
        Console.WriteLine("Radiani: " + r);
    }

    static double Attalums(double x1, double y1, double x2, double y2)
    {
        double dx = x2 - x1;
        double dy = y2 - y1;
        return Math.Sqrt(dx * dx + dy * dy);
    }

    static double Radiani(double g)
    {
        return g * (Math.PI / 180);
    }
}

class Program
{
    static void Main()
    {
        Console.WriteLine("1 - Izdevumu programma");
        Console.WriteLine("2 - Noliktava");
        Console.WriteLine("3 - Attaluma programma");
        Console.Write("Izvele: ");

        string v = Console.ReadLine();

        switch (v)
        {
            case "1":
                IzdevumuPrograma.Run();
                break;
            case "2":
                NoliktavaPrograma.Run();
                break;
            case "3":
                AttalumaPrograma.Run();
                break;
            default:
                Console.WriteLine("Nepareiza izvele");
                break;
        }
    }
}
