// Adrians Zemturis
// Grupa: 110
// PR: 7.0
// Kompilators: Online GDP
// https://www.onlinegdb.com/online_csharp_compiler

using System;
using System.Collections.Generic;

class HelloWorld {
     // Mēneša budžeta analīze un filtri | 1 UZD |
	static List<double> InputExpense() {
		string Input = "";
		double InputedExpense = 0;
		List<double> Expenses = new List<double>();

		bool Inputing = true;
		while (Inputing) {
			Console.Clear();
			Console.Write("Uzrakstiet (bez pedinam): 'iziet', lai beigtu ievadi. \nIevadiet izdevumu: ");
			Input = Console.ReadLine();

			if (double.TryParse(Input, out InputedExpense)) {
				Expenses.Add(InputedExpense);
			}
			else {
				if (Input.ToLower() == "iziet") {
					Inputing = false;
				}
			}
		}
		return Expenses;
	}

	static List<double> FilterExpenses(List<double> ExitData, double Threshold) {
		List<double> FilteredData = new List<double>();

		foreach (double expense in ExitData) {
			if (expense < Threshold) {
				continue;
			}
			FilteredData.Add(expense);
		}

		return FilteredData;
	}

	static double CalculateChange(List<double> FilteredData) {
		double range = 0;
		double min = 0;
		double max = 0;

		if (FilteredData.Count > 0) {
			min = FilteredData[0];
			max = FilteredData[0];
			foreach (double value in FilteredData) {
				if (value < min) {
					min = value;
				}
				if (value > max) {
					max = value;
				}
			}
			range = Math.Abs(max - min);

		}
		return range;
	}

    
	// Preču meklētājs noliktavā | 2 UZD |
    static string FindProduct(string[,] Noliktava, string ProductToFind) {
        string Coordinates = "Nevareja atrast preci!";
        bool searching = true;
        
        for (int aisle = 0; aisle < Noliktava.GetLength(0); aisle++) {
            for (int shelf = 0; shelf < Noliktava.GetLength(1); shelf++) {
                if (Noliktava[aisle, shelf] == ProductToFind) {
                    searching = false;
                    Coordinates = $"Prece atrasta Eja: {aisle + 1}, Plaukta: {shelf + 1}";
                    break;
                }
            }
            if (searching == false) {
                break;
            }
        }
        
        return Coordinates;
    }
    
    static int GetEmptyShelves(string[,] Noliktava) {
        int EmtpyShelves = 0;

        for (int aisle = 0; aisle < Noliktava.GetLength(0); aisle++) {
            for (int shelf = 0; shelf < Noliktava.GetLength(1); shelf++) {
                if (string.IsNullOrEmpty(Noliktava[aisle, shelf])) {
                    EmtpyShelves += 1;
                }
            }
        }
        
        return EmtpyShelves;
    }

    // Attāluma kalkulators plaknē | 3 UZD |
    static double GetDistance((double x, double y) A, (double x, double y) B) {
        double Distance = 0;

        Distance = Math.Sqrt(Math.Pow(B.x - A.x, 2) + Math.Pow(B.y - A.y, 2));
        
        return Distance;
    }
    
    static double ConvertToRadians(double deg) {
        double Radians = 0;

        Radians = deg * (Math.PI/180);
        
        return Radians;
    }
    
	static void Main() {
        string Input = "";
        bool Inputing = true;
	    // Mēneša budžeta analīze un filtri | 1 UZD |

		List<double> Expenses = new List<double>();
		Expenses = InputExpense();

		double Threshold = 0;
		while (Inputing) {
			Console.Clear();
			Console.Write("Ievadiet slieksni: ");
			Input = Console.ReadLine();
			if (double.TryParse(Input, out Threshold)) {
				Inputing = false;
			}
		}
	
		Expenses = FilterExpenses(Expenses, Threshold);
		double Range = CalculateChange(Expenses);
		Console.Write($"Starp max, un min ir: {Range}");
		
		
		// Preču meklētājs noliktavā | 2 UZD |
		Console.ReadKey();
		Console.Clear();
		
		string[,] Noliktava = {
		    {null, "gemstone"},
            {"potato", "galvenized square steel"},
            {"bean", ""},
            {"six bedroom nine bathroom beverly hills mansion", "pipe bomb"},
		};
		
		Inputing = true;
        while (Inputing) {
            Console.Clear();
            Console.WriteLine("Ievadiet preci: ");
            Input = Console.ReadLine();
            if (string.IsNullOrEmpty(Input) == false) {
                Inputing = false;
                Input = Input.ToLower();
            }
        }
		string Coordinates = FindProduct(Noliktava, Input);
		Console.WriteLine(Coordinates);
		int EmtpyShelves = GetEmptyShelves(Noliktava);
	    Console.WriteLine($"Noliktava ir {EmtpyShelves} tuksi plaukti.");	

	    // Attāluma kalkulators plaknē | 3 UZD |
		Console.ReadKey();
		Console.Clear();
		
		(double x, double y) A = (0, 0);
	    (double x, double y) B = (0, 0);
		
		bool inputing_a = true;
		bool inputing_b = true;
		Inputing = true;
		while (Inputing) {
			Console.Clear();

			if (inputing_a) {
			    Console.Write("Ievadiet A, x vertibu: ");
			    Input = Console.ReadLine();
		    	if (double.TryParse(Input, out double val)) {
				    A.x = val;
			    }
			    else
			    {
			        continue;
			    }
			    Console.Write("Ievadiet A, y vertibu: ");
			    Input = Console.ReadLine();
		    	if (double.TryParse(Input, out val)) {
				    A.y = val;
			    }
			    else {
			        continue;
			    }
			    
			    inputing_a = false;
			}
			
			if (inputing_b) {
			    Console.Write("Ievadiet B, x vertibu: ");
			    Input = Console.ReadLine();
		    	if (double.TryParse(Input, out double val)) {
				    B.x = val;
			    }
			    else {
			        continue;
			    }
			    Console.Write("Ievadiet B, y vertibu: ");
			    Input = Console.ReadLine();
		    	if (double.TryParse(Input, out val)) {
				    B.y = val;
			    }
			    else {
			        continue;
			    }
			    inputing_b = false;
			}
			Inputing = false;
		}
		
		double Distance = GetDistance(A, B);
		Console.WriteLine(Distance);
		
		Console.ReadKey();
		double Degrees = 0;
		Inputing = true;
		while (Inputing) {
			Console.Clear();
			Console.Write("Ievadiet lenki grados: ");
			Input = Console.ReadLine();
			if (double.TryParse(Input, out Degrees)) {
				Inputing = false;
			}
		}
		
		double Radians = ConvertToRadians(Degrees);
		Console.WriteLine($"{Degrees} gradi ir {Radians} radiani.");
	}
}