/*
Rūdolfs Čābūts
Praktiskais darbs 6.3
https://www.onlinegdb.com

*/

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

class HelloWorld
{
    static void Main()
    {
        List<double> ievades = new List<double>();
        Console.WriteLine("Ievadi izdevumu summu:");
        IevadietIzdevumus(ievades);  //1. Metode
        foreach (double i in ievades)
        {
            Console.WriteLine(i);
        }

        List<double> ievadesFiltrets = new List<double>();

        FiltretIzdevumus(ievades, ievadesFiltrets);   // 2. Metode
        Console.WriteLine("\nFiltretie izdevumi:");
        foreach (double i in ievadesFiltrets)
        {
            Console.WriteLine(i);
        }

        AprekinatMainibu(ievadesFiltrets);   // 3. Metode

        string[,] noliktava =
        {
            {"1-A", "1-B", "1-C", "1-D", "1-E"},
            {"2-A", "2-B", "2-C", "2-D", "2-E"},
            {"3-A", "3-B", "3-C", "3-D", "3-E"},
            {"4-A", "4-B", "4-C", "4-D", "4-E"}
        };

        Console.WriteLine("\nIevadi preces kodu: ");
        string kods = Console.ReadLine();

        kods = ParveidotKodu(kods);

        string rezultats = AtklatPreci(noliktava, kods);
        Console.WriteLine(rezultats);                  //4. Metode

        Console.WriteLine("\nIevadi x1:");
        double x1 = double.Parse(Console.ReadLine());

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

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

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

        double attalums = AprekinatPlaknesAttalumu(x1, y1, x2, y2);
        Console.WriteLine("Attālums starp punktiem: " + attalums);  //5. Metode

        Console.WriteLine("\nIevadi leņķi grādos:");
        double gradi = double.Parse(Console.ReadLine());

        double radiani = KonvertetRadianos(gradi);
        Console.WriteLine("Leņķis radiānos: " + radiani);           //6. Metode
    }

    static void IevadietIzdevumus(List<double> ievades)
    {
        bool beigt = false;
        while (beigt == false)
        {
            string ievade = Console.ReadLine();
            if (ievade == "beigt" || ievade == " " || ievade == "")
            {
                beigt = true;
            }
            else
            {
                ievades.Add(Convert.ToDouble(ievade));
            }
        }
    }

    static void FiltretIzdevumus(List<double> ievades, List<double> ievadesFiltrets)
    {
        foreach (double i in ievades)
        {
            if (i >= 3.5)
            {
                ievadesFiltrets.Add(i);
            }
        }
    }

    static void AprekinatMainibu(List<double> ievadesFiltrets)
    {
        double filtretsMin = ievadesFiltrets.Min();
        double filtretsMax = ievadesFiltrets.Max();
        double filtretsRange = filtretsMax - filtretsMin;
        Console.WriteLine("Filtretais diapazons: " + filtretsRange);
    }

    static string AtklatPreci(string[,] noliktava, string kods)
    {
        for (int i = 0; i < noliktava.GetLength(0); i++)
        {
            for (int j = 0; j < noliktava.GetLength(1); j++)
            {
                if (noliktava[i, j] == kods)
                {
                    return $"Atrodas: {i + 1}, {j + 1}";
                }
            }
        }
        return "Prece nav atrasta.";
    }

    static string ParveidotKodu(string kods)
    {
        kods = kods.Replace(" ", "");
        kods = kods.ToUpper();

        if (kods.Length == 2)
        {
            kods = kods[0] + "-" + kods[1];
        }

        return kods;
    }

    static double AprekinatPlaknesAttalumu(double x1, double y1, double x2, double y2)
    {
        double dx = x2 - x1;
        double dy = y2 - y1;

        double distance = Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2));
        return distance;
    }

    static double KonvertetRadianos(double gradi)
    {
        return gradi * (Math.PI / 180);
    }
}
