Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace Ruoðimasis_egzaminui_1
- {
- class Butas
- {
- public string Adresas { get; set; }
- public double Plotas { get; set; }
- public int KambSk { get; set; }
- public Butas(string adresas, double plotas, int kambSk)
- {
- this.Adresas = adresas;
- this.Plotas = plotas;
- this.KambSk = kambSk;
- }
- }
- class Namas
- {
- public const int MaxButuSk = 100;
- public Butas[] Butai { get; set; }
- public int CountButai { get; set; }
- public double didButas {get; set; }
- public Namas()
- {
- Butai = new Butas[MaxButuSk];
- }
- public void AddButai(Butas but)
- {
- Butai[CountButai] = but;
- CountButai++;
- }
- public double DidziausiasButas()
- {
- double max = Butai[0].Plotas; ;
- for (int i = 1; i < CountButai; i++)
- {
- if (Butai[i].Plotas > max)
- {
- max = Butai[i].Plotas;
- }
- }
- Console.WriteLine(max);
- return max;
- }
- }
- class Program
- {
- const int MaxNamaiNumb = 100;
- static void Main(string[] args)
- {
- int count = 0;
- Namas[] N = new Namas[MaxNamaiNumb];
- ReadAllButaiData("Butas.txt", ref N, ref count);
- for (int i = 0; i < count; i++)
- {
- N[i].didButas = N[i].DidziausiasButas();
- Console.WriteLine("Didziausio buto name dydis: " + N[i].didButas);
- }
- }
- private static void ReadAllButaiData(string file, ref Namas[] N, ref int count)
- {
- using (StreamReader reader = new StreamReader(file, System.Text.Encoding.GetEncoding(1257)))
- {
- string line = null;
- line = reader.ReadLine();
- while ((line != null) && (line.Contains(';')))
- {
- N[count] = new Namas();
- string[] value = line.Split(';');
- string adresas = value[0];
- double plotas = double.Parse(value[1]);
- int kambSk = int.Parse(value[2]);
- Butas but = new Butas(adresas, plotas, kambSk);
- if (!N[count].Butai.Contains(but))
- {
- N[count].AddButai(but);
- }
- line = reader.ReadLine();
- count++;
- }
- }
- }
- static double MaxButoPlotas(Namas N)
- {
- double max = N.Butai[0].Plotas; ;
- for (int i = 1; i < N.CountButai; i++)
- {
- if (N.Butai[i].Plotas > max)
- {
- max = N.Butai[i].Plotas;
- }
- }
- Console.WriteLine(max);
- return max;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment