Advertisement
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 ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- string plik = "karetki.txt";
- StreamReader r = new StreamReader(plik);
- int n = int.Parse(r.ReadLine());
- string dl=r.ReadLine();
- string[] dlugosc = dl.Split(';');
- int x = dlugosc[1].Length;
- r.Close();
- string[] identyfikatory= new string[n];
- int[] stanPocz= new int[x];
- int[] stanKoniec= new int[x];
- WczytajDane(plik,identyfikatory, stanPocz, stanKoniec);
- int[] dystans= new int[n];
- dystans=ObliczDystans(stanPocz,stanKoniec);
- Console.Write("\n");
- for (int i = 0; i < dystans.Length; i++)
- {
- Console.WriteLine("{0} - {1} = {2}",stanKoniec[i],stanPocz[i],dystans[i]);
- }
- int srDystans=ObliczSredniDystans(dystans);
- Console.WriteLine("Średni dystans to: {0}",srDystans);
- string maxDystans = ZnajdzKaretke(identyfikatory, dystans);
- Console.WriteLine("Najwiekszy dzienny dystans pokonała karetka o identyfikatorze: {0}", maxDystans);
- string karetka = WyswielInformacje(maxDystans, identyfikatory, stanPocz, stanKoniec, dystans);
- Console.ReadKey();
- }static void WczytajDane(string plik, string[] identyfikatory, int[] stanPocz, int[] stanKoniec)
- {
- StreamReader re = new StreamReader(plik);
- int a = int.Parse(re.ReadLine());
- int ind = 0;
- int pocz = 1;
- int kon = 2;
- for (int i = 0; i < a; i++)
- {
- string nap = re.ReadLine();
- string[] all = nap.Split(';');
- identyfikatory[i] = all[ind];
- Console.WriteLine(identyfikatory[i]);
- stanPocz[i] = int.Parse(all[pocz]);
- Console.WriteLine(stanPocz[i]);
- stanKoniec[i] = int.Parse(all[kon]);
- Console.WriteLine(stanKoniec[i]);
- }
- re.Close();
- }
- static int[] ObliczDystans(int[] stanPocz, int[] stanKoniec)
- {
- int[] tab = new int[stanPocz.Length];
- for (int i = 0; i < stanPocz.Length; i++)
- {
- tab[i] = stanKoniec[i] - stanPocz[i];
- }
- return tab;
- }
- static int ObliczSredniDystans(int[] dystans)
- {
- int suma = 0;
- for (int i = 0; i < dystans.Length; i++)
- {
- suma += dystans[i];
- }
- int wynik = suma / (dystans.Length);
- return wynik;
- }
- static string ZnajdzKaretke(string [] identyfikatory, int[] dystans)
- {
- int Licznik = 0;
- int max = dystans[0];
- for (int i = 0; i < dystans.Length;i++)
- {
- if (max < dystans[i])
- {
- max = dystans[i];
- Licznik = i;
- }
- }
- return identyfikatory[Licznik];
- }
- static string WyswielInformacje(string maxDystans,string[] identyfikatory, int[] stanPocz, int[] stanKoniec, int[] dystans)
- {
- int Licznik = 0;
- int max = dystans[0];
- for (int i = 0; i < dystans.Length; i++)
- {
- if (max < dystans[i])
- {
- max = dystans[i];
- Licznik = i;
- }
- }
- string karetka = identyfikatory[Licznik] + " " + stanKoniec[Licznik] + " - " + stanPocz[Licznik] + " Dystans: " + max;
- return karetka;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement