/*
Veidoja: Mikus Tolkačevs
Grupa:110
Praktiskais darbs 7
Izmantotais compiler:https://www.programiz.com/csharp-programming/online-compiler/
*/
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        List<double> izdevumi = IevadietIzdevumus();
        Console.Write("Ievadiet filtra slieksni: ");
        double slieksnis;
        if (Double.TryParse(Console.ReadLine(), out slieksnis))
        {
            List<double> filtrēti = FiltretIzdevumus(izdevumi, slieksnis);
            if (filtrēti.Count > 0)
            {
                double diapazons = AprekinatMainibu(filtrēti);
                Console.WriteLine($"Filtreto izdevumu diapazons: {diapazons}");
            }
            else
            {
                Console.WriteLine("Pec filtresanas nav palikusi izdevumi");
            }
        }
        else
        {
            Console.WriteLine("Nepareizi ievadits slieksnis");
        }
        string[,] noliktava = new string[4,5]
        {
     { "SIX67", "", "89PLS", "", "ABV85"},
     { "", "PKA54", "", "DGV54", ""},
     { "ONE11", "", "TWO22", "", "SEE33"},
     { "", "YES67", "", "NAH52", ""}
        };
        Console.Write("Ievadiet meklejamo preces kodu: ");
        string kods = Console.ReadLine();
        string rez = AtklatPreci(noliktava, kods);
       Console.WriteLine(rez);
        int tuksi = AprekinatNeaizpilditas(noliktava);
        Console.WriteLine($"Noliktava tukso plauktu skaits: {tuksi}");
        double x1, y1, x2, y2;

Console.Write("Ievadiet x1: ");
while (!double.TryParse(Console.ReadLine(), out x1))
    Console.Write("Nederiga vertiba! Ievadi x1: ");

Console.Write("Ievadiet y1: ");
while (!double.TryParse(Console.ReadLine(), out y1))
    Console.Write("Nederiga vertiba! Ievadi y1: ");

Console.Write("Ievadiet x2: ");
while (!double.TryParse(Console.ReadLine(), out x2))
    Console.Write("Nederiga vertiba! Ievadi x2 : ");

Console.Write("Ievadiet y2: ");
while (!double.TryParse(Console.ReadLine(), out y2))
    Console.Write("Nederiga vertiba! Ievadi y2: ");



        double dist = AprekinatPlaknesAttalumu(x1, y1, x2, y2);
        Console.WriteLine($"Attalums starp punktiem: {dist}");
        double gradi;

Console.Write("Ievadiet gradus: ");
while (!double.TryParse(Console.ReadLine(), out gradi))
    Console.Write("Nederiga vertiba! Ievadi velreiz: ");

double radi = KonvertetRadianos(gradi);
Console.WriteLine($"{gradi} gradi radianos = {radi}");

    }
    static List<double> IevadietIzdevumus()
    {
        List<double> saraksts = new List<double>();
        Console.WriteLine("Ievadiet izdevumu summu (Nospieziet Enter vai uzrakstiet  \"gals\" lai beigtu):");
        while (true)
        {
            Console.Write("Summa: ");
            string line = Console.ReadLine();
            if (String.IsNullOrWhiteSpace(line) || line.Trim().ToLower() == "gals")
                break;
            double val;
            if (Double.TryParse(line, out val))
            {
                saraksts.Add(val);
            }
            else
            {
                Console.WriteLine("Nepareizs skaitla formats");
            }
        }
        return saraksts;
    }

    static List<double> FiltretIzdevumus(List<double> izejasDati, double slieksnis)
    {
        List<double> filtrēti = new List<double>();
        foreach (double d in izejasDati)
        {
            if (d < slieksnis)
            {
                continue; 
            }
            filtrēti.Add(d);
        }
        return filtrēti;
    }

    static double AprekinatMainibu(List<double> dati)
    {
        double min = double.MaxValue;
        double max = double.MinValue;
        foreach (double d in dati)
        {
            if (d < min) min = d;
            if (d > max) max = d;
        }
        double diff = Math.Abs(max - min);
        return diff;
    }
    static string AtklatPreci(string[,] masivs, string kods)
    {
        int rows = masivs.GetLength(0);
        int cols = masivs.GetLength(1);
        for (int eja = 0; eja < rows; eja++)
        {
            for (int plaukts = 0; plaukts < cols; plaukts++)
            {
                if (masivs[eja, plaukts] == kods)
                {
                    return $"Prece atrasta Eja {eja + 1}, Plaukts {plaukts + 1}";
                }
            }
        }
        return "Prece nav atrasta noliktava.";
    }
    static int AprekinatNeaizpilditas(string[,] masivs)
    {
        int count = 0;
        int rows = masivs.GetLength(0);
        int cols = masivs.GetLength(1);
        for (int eja = 0; eja < rows; eja++)
        {
            for (int plaukts = 0; plaukts < cols; plaukts++)
            {
                if (String.IsNullOrEmpty(masivs[eja, plaukts]))
                {
                    count++;
                }
            }
        }
        return count;
    }
    static double AprekinatPlaknesAttalumu(double x1, double y1, double x2, double y2)
    {
        double dx = x2 - x1;
        double dy = y2 - y1;
        double d = Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2));
        return d;
    }
    static double KonvertetRadianos(double gradi)
    {
        return gradi * Math.PI / 180.0;
    }
}
