Advertisement
Guest User

futar.cs

a guest
May 18th, 2012
1,306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.IO;
  5.  
  6. namespace fuvar
  7. {
  8.     class Fuvar
  9.     {
  10.         public int nap;
  11.         public int sorszam;
  12.         public int tav;
  13.  
  14.         public int ar
  15.         {
  16.             get
  17.             {
  18.                 if (tav<=2) return 500;
  19.                 if (tav<=5) return 700;
  20.                 if (tav<=10) return 900;
  21.                 if (tav<=20) return 1400;
  22.                 return 2000;
  23.             }
  24.         }
  25.  
  26.         public Fuvar(string be)
  27.         {
  28.             string[] besplit = be.Split(' ');
  29.             nap = Convert.ToInt32(besplit[0]);
  30.             sorszam = Convert.ToInt32(besplit[1]);
  31.             tav = Convert.ToInt32(besplit[2]);
  32.         }
  33.  
  34.         public Fuvar(int be)
  35.         {
  36.             tav = be;
  37.         }
  38.     }
  39.  
  40.     class Program
  41.     {
  42.         static void Main()
  43.         {
  44.             string[] nyersadat = File.ReadAllLines(@"tavok.txt");
  45.             List<Fuvar> adatok = new List<Fuvar>();
  46.             foreach (string x in nyersadat)
  47.             {
  48.                 adatok.Add(new Fuvar(x));
  49.             }
  50.             List<Fuvar> rendezettadatok = adatok.OrderBy(x => x.nap).ThenBy(y => y.sorszam).ToList();
  51.             Console.Write("2. feladat:\nA hét első útja {0} km volt.\n", rendezettadatok.First().tav);
  52.             Console.Write("3. feladat:\nA hét utolsó útja {0} km volt.\n", rendezettadatok.Last().tav);
  53.             int[] napikm = new int[7];
  54.             foreach (Fuvar x in rendezettadatok)
  55.             {
  56.                 napikm[x.nap - 1] += x.tav;
  57.             }
  58.             Console.Write("4. feladat:\nA futár szünetett tartott a(z) ");
  59.             for (int i = 0; i < 7; i++)
  60.             {
  61.                 if (napikm[i]==0)
  62.                 {
  63.                     Console.Write("{0}., ", i + 1);
  64.                 }
  65.             }
  66.             Console.Write("\b\b napokon(napon).\n");
  67.             Console.Write("5. feladat:\nA legtöbb fuvar a(z) {0}. napon volt.\n", adatok.OrderByDescending(x => x.sorszam).First().nap);
  68.             Console.Write("6. feladat:\nAz egyes napokon megtett út:\n");
  69.             for (int i = 0; i < 7; i++)
  70.             {
  71.                 Console.Write("{0}. nap: {1} km\n",i+1,napikm[i]);
  72.             }
  73.             Console.Write("7. feladat:\nAdjon meg egy tetszőleges távot: ");
  74.             Console.Write("Ezért az útért {0} Ft jár.\n", new Fuvar(Convert.ToInt32(Console.ReadLine())).ar);
  75.             StreamWriter ki = new StreamWriter(@"dijazas.txt");
  76.             foreach (Fuvar x in rendezettadatok)
  77.             {
  78.                 ki.WriteLine("{0}. nap {1}. út: {2} Ft", x.nap, x.sorszam, x.ar);
  79.             }
  80.             ki.Close();
  81.             int osszesdij = 0;
  82.             foreach (Fuvar x in rendezettadatok)
  83.             {
  84.                 osszesdij += x.ar;
  85.             }
  86.             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);
  87.             Console.ReadKey();
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement