/*
Autors: Andrejs Šorecs
Grupa: 110
Praktiskais darbs: 7
Izmantotais Compilar: https://www.programiz.com/csharp-programming/online-compiler/
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Praktiskais_darbs_7
{
    public class Task1
    {
        public static void Main1()
        {
            double slieksnis = 10;
            List<double> IzejasDati = new List<double>();
            List<double> dati = new List<double>();
            List<double> izdevumi = IevadietIzdevumus();
            Console.WriteLine("Ievaditie izdevumi:");
            foreach (double i in izdevumi)
            {
                Console.WriteLine(i);
            }
            FiltretIzdevumus(izdevumi, IzejasDati, slieksnis);
            Console.WriteLine("Izejas Dati");
            foreach (double k in IzejasDati)
            {
                Console.WriteLine(k);
            }

            Console.WriteLine("diapazons " + ApreikinatMainibu(IzejasDati, dati));
            Console.WriteLine("dati");
            foreach (double m in dati)
            {
                Console.WriteLine(m);
            }
            Console.ReadKey();
        }
        public static List<double> IevadietIzdevumus()
        {
            List<double> izdevumi = new List<double>();
            bool IeIzd = true;
            Console.WriteLine("Ievadiet izdevumu summu! ievadot komandu gals vai tuksu kopu ievade beigsies");
            while (IeIzd)
            {
                string ievade = Console.ReadLine();
                if (ievade.ToLower() == "gals")
                {
                    IeIzd = false;
                }
                if (string.IsNullOrWhiteSpace(ievade))
                {
                    IeIzd = false;
                }

                if (Double.TryParse(ievade, out double izd))
                {
                    izdevumi.Add(izd);
                }
            }
            return izdevumi;
        }
        public static List<double> FiltretIzdevumus(List<double> izdevumi, List<double> IzejasDati, double slieksnis)
        {
            IzejasDati.Clear();
            foreach (double k in izdevumi)
            {
                if (k < slieksnis)
                {
                    continue;
                }
                IzejasDati.Add(k);
            }
            return IzejasDati;
        }
        public static double ApreikinatMainibu(List<double> IzejasDati, List<double> dati)
        {
            foreach (double i in IzejasDati)
            {
                dati.Add(i);
            }
            double range = (Math.Abs(dati.Max()) - Math.Abs(dati.Min()));
            return range;

        }
    }

    public class Task2
    {
        public static void Main2()
        {
            string[,] noliktava = { {"47","16","82","91" },{"51","","67","52" } };
            string kods;
            AprekinatNeaizpilditas(noliktava);
            AtklatPreci(noliktava, out kods);
            Console.ReadKey();
        }
        public static string AtklatPreci(string[,] noliktava, out string kods)
        {
            for (int i= 0; i<noliktava.GetLength(0); i++)
            {
                for (int j= 0; j<noliktava.GetLength(1); j++)
                {
                }
            }
            bool cikls=true;
            do
            {
                Console.WriteLine("Ievadiet precu kodu tas ir no 1 lidz 100");
                kods = Console.ReadLine();
                for (int i = 0; i < noliktava.GetLength(0); i++)
                {
                    for (int j = 0; j < noliktava.GetLength(1); j++)
                    {
                        if (noliktava[i, j] == kods)
                        {
                            Console.WriteLine($"Precu kods {kods} atrasts Eja {i} un Plaukta {j} ");
                            cikls = false; 
                        }
                    }
                }
                if(cikls == true)
                {
                    Console.WriteLine("Prece nav atrasta!");
                }
            }
            while (cikls);
            return kods;
        }
        public static int AprekinatNeaizpilditas(string[,] noliktava)
        {
            int tpl = 0;
            for (int i= 0;i<noliktava.GetLength(0);i++)
            {
                for(int j= 0; j< noliktava.GetLength(1);j++)
                {
                    if (noliktava == null)
                    {
                       tpl = tpl + 1;
                    }
                }
            }
            Console.WriteLine($"Veikalu tukso plauktu ir {tpl}");
            return tpl;
        }
    }

    public class Task3
    {
        public static void Main3()
        {
            AprekinatPlaknesAttalumu();
            KonvertetRadianos();
            Console.ReadKey();
        }
        public static double AprekinatPlaknesAttalumu()
        {
            Console.WriteLine("Ievadiet (x1;x2) un (y1;y2) vertibas!");
            int x1 = Convert.ToInt32(Console.ReadLine());
            int x2 = Convert.ToInt32(Console.ReadLine());
            int y1 = Convert.ToInt32(Console.ReadLine());
            int y2 = Convert.ToInt32(Console.ReadLine());
            double d = Math.Sqrt(Math.Pow((x2-x1),2)+Math.Pow((y2-y1),2));
            Console.WriteLine("Attalums starp siem punktiem "+ d);
            return d;
        }
        public static double KonvertetRadianos()
        {
            Console.WriteLine("Ievadiet gradus");
            double gradi=Convert.ToDouble(Console.ReadLine());
            double radiani = gradi*(Math.PI/180);
            Console.WriteLine("radiani " + radiani);
            return radiani;
        }
    }

}