using System.IO;

DataRead();
Varos legmelegebb = Legmelegebb();
Console.WriteLine($"Legmelegebb: {legmelegebb.Nev} {legmelegebb.Homerseklet}");
Varos leghidegebb = Leghidegebb();
Console.WriteLine($"Leghidegebb: {leghidegebb.Nev} {leghidegebb.Homerseklet}");
double atlag = Atlag();
Console.WriteLine($"Átlag hőmérséklet: {atlag:F2}");
//list városok where homerseklet > 20
Console.WriteLine("20°C-nál melegebb városok:");
foreach (var item in Meleg())
{
    Console.WriteLine($"\t{item.Nev}: {item.Homerseklet}°C");
}


static IEnumerable<Varos> Meleg()
{
    return Data.varosok.Where(x => x.Homerseklet > 20);
} 
static double Atlag()
{
    return Data.varosok.Average(x => x.Homerseklet);
}

static Varos Leghidegebb()
{
    var legmelegebb = Data.varosok.OrderBy(x => x.Homerseklet).Take(1);
    return legmelegebb.First();
} 

static Varos Legmelegebb()
{
    var legmelegebb = Data.varosok.OrderByDescending(x => x.Homerseklet).Take(1);
    return legmelegebb.First();
} 

static void DataRead()
{
    string path = "E:\\Házi\\Programozás\\C#\\Suli\\ProgaOra\\20240920\\ConsoleApp2\\ConsoleApp2\\bin\\Debug\\varosok.txt";
    using (StreamReader streamReader = new StreamReader(path))
    {
        string line = streamReader.ReadLine();
        line = streamReader.ReadLine();

        while (line != null)
        {
            string[] datas = line.Split(',');
            Varos varos = new Varos(datas[0], Convert.ToInt32(datas[1]));
            Data.varosok.Add(varos);
            line = streamReader.ReadLine();
        }

    }
}



public class Varos
{
    public string Nev;
    public int Homerseklet;

    public Varos(string nev, int homerseklet)
    {
        Nev = nev;
        Homerseklet = homerseklet;
    }
}

public static class Data
{
    public static List<Varos> varosok = new List<Varos>();
}