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.IO;
- namespace fuvar
- {
- class Fuvar
- {
- public int nap;
- public int sorszam;
- public int tav;
- public int ar
- {
- get
- {
- if (tav<=2) return 500;
- if (tav<=5) return 700;
- if (tav<=10) return 900;
- if (tav<=20) return 1400;
- return 2000;
- }
- }
- public Fuvar(string be)
- {
- string[] besplit = be.Split(' ');
- nap = Convert.ToInt32(besplit[0]);
- sorszam = Convert.ToInt32(besplit[1]);
- tav = Convert.ToInt32(besplit[2]);
- }
- public Fuvar(int be)
- {
- tav = be;
- }
- }
- class Program
- {
- static void Main()
- {
- string[] nyersadat = File.ReadAllLines(@"tavok.txt");
- List<Fuvar> adatok = new List<Fuvar>();
- foreach (string x in nyersadat)
- {
- adatok.Add(new Fuvar(x));
- }
- List<Fuvar> rendezettadatok = adatok.OrderBy(x => x.nap).ThenBy(y => y.sorszam).ToList();
- Console.Write("2. feladat:\nA hét első útja {0} km volt.\n", rendezettadatok.First().tav);
- Console.Write("3. feladat:\nA hét utolsó útja {0} km volt.\n", rendezettadatok.Last().tav);
- int[] napikm = new int[7];
- foreach (Fuvar x in rendezettadatok)
- {
- napikm[x.nap - 1] += x.tav;
- }
- Console.Write("4. feladat:\nA futár szünetett tartott a(z) ");
- for (int i = 0; i < 7; i++)
- {
- if (napikm[i]==0)
- {
- Console.Write("{0}., ", i + 1);
- }
- }
- Console.Write("\b\b napokon(napon).\n");
- Console.Write("5. feladat:\nA legtöbb fuvar a(z) {0}. napon volt.\n", adatok.OrderByDescending(x => x.sorszam).First().nap);
- Console.Write("6. feladat:\nAz egyes napokon megtett út:\n");
- for (int i = 0; i < 7; i++)
- {
- Console.Write("{0}. nap: {1} km\n",i+1,napikm[i]);
- }
- Console.Write("7. feladat:\nAdjon meg egy tetszőleges távot: ");
- Console.Write("Ezért az útért {0} Ft jár.\n", new Fuvar(Convert.ToInt32(Console.ReadLine())).ar);
- StreamWriter ki = new StreamWriter(@"dijazas.txt");
- foreach (Fuvar x in rendezettadatok)
- {
- ki.WriteLine("{0}. nap {1}. út: {2} Ft", x.nap, x.sorszam, x.ar);
- }
- ki.Close();
- int osszesdij = 0;
- foreach (Fuvar x in rendezettadatok)
- {
- osszesdij += x.ar;
- }
- Console.Write("9. feladat:\nA heti munkáért a futár {0} Ft díjízást kapott.\nA befejezéshez nyomjon le egy billentyűt! ", osszesdij);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement