Levi0227

SuperBowl-ConsoleApp(+class)-2022maj

Apr 22nd, 2023 (edited)
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.90 KB | Source Code | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8.  
  9. namespace SuperBowl
  10. {
  11.     class RomaiSorszam
  12.     {
  13.         public string RomaiSsz { get; private set; }
  14.  
  15.         private static Dictionary<char, int> RomaiMap = new Dictionary<char, int>()
  16.     {
  17.         {'I', 1}, {'V', 5}, {'X', 10}, {'L', 50}, {'C', 100}, {'D', 500}, {'M', 1000}
  18.     };
  19.  
  20.         public string ArabSsz
  21.         {
  22.             get
  23.             {
  24.                 int ertek = 0;
  25.                 string romaiSzam = RomaiSsz.TrimEnd('.');
  26.                 for (int i = 0; i < romaiSzam.Length; i++)
  27.                 {
  28.                     if (i + 1 < romaiSzam.Length &&
  29.                         RomaiMap[romaiSzam[i]] < RomaiMap[romaiSzam[i + 1]])
  30.                     {
  31.                         ertek -= RomaiMap[romaiSzam[i]];
  32.                     }
  33.                     else
  34.                     {
  35.                         ertek += RomaiMap[romaiSzam[i]];
  36.                     }
  37.                 }
  38.                 return $"{ertek}.";
  39.             }
  40.         }
  41.  
  42.         public RomaiSorszam(string romaiSsz)
  43.         {
  44.             RomaiSsz = romaiSsz.ToUpper();
  45.         }
  46.     }
  47.  
  48.     class C_SuperBowl
  49.     {
  50.         public string SorSz, datum, gyoztes, vesztes, helyszin, varosallam;
  51.         public int gyoztes_pont, vesztes_pont, nezoszam;
  52.  
  53.         public C_SuperBowl(string sor)
  54.         {
  55.             string[] egysor = sor.Split(';');
  56.  
  57.             SorSz = egysor[0];
  58.             datum = egysor[1];
  59.             gyoztes = egysor[2];
  60.             gyoztes_pont = Convert.ToInt32(egysor[3].Split('-')[0]);
  61.             vesztes_pont = Convert.ToInt32(egysor[3].Split('-')[1]);
  62.             vesztes = egysor[4];
  63.             helyszin = egysor[5];
  64.             varosallam = egysor[6];
  65.             nezoszam = Convert.ToInt32(egysor[7]);
  66.         }
  67.     }
  68.     class SuperBowl
  69.     {
  70.         static List<C_SuperBowl> adatok = new List<C_SuperBowl>();
  71.  
  72.         static void Ex2()
  73.         {
  74.             StreamReader sr = new StreamReader("SuperBowl.txt");
  75.             string fejlec=sr.ReadLine();
  76.             while (!sr.EndOfStream)
  77.             {
  78.  
  79.                 adatok.Add(new C_SuperBowl(sr.ReadLine()));
  80.             }
  81.             sr.Close();
  82.             //foreach (var e in adatok)
  83.             //{
  84.             //    Console.WriteLine($"{e.gyoztes_pont}");
  85.             //}
  86.             StreamWriter sw = new StreamWriter("SuperBowlNew.txt");
  87.             sw.WriteLine(fejlec);
  88.             List<string> tempgy = new List<string>();
  89.             int gyoztesdb = 0;
  90.             int vesztesdb = 0;
  91.             for (int i = 0; i < adatok.Count; i++)
  92.             {
  93.                 for (int j = 0; j < tempgy.Count; j++)
  94.                 {
  95.                     if (tempgy[j].Contains(adatok[i].gyoztes))
  96.                     {
  97.                         gyoztesdb++;
  98.                     }
  99.                     if (tempgy[j].Contains(adatok[i].vesztes))
  100.                     {
  101.                         vesztesdb++;
  102.                     }
  103.                 }
  104.                     string gyoztescsap = adatok[i].gyoztes + "(" + gyoztesdb.ToString() + ")";
  105.                     string vesztescsap = adatok[i].vesztes + "(" + vesztesdb.ToString() + ")";
  106.                     tempgy.Add(adatok[i].SorSz + ";" + adatok[i].datum +";" + gyoztescsap + ";" + adatok[i].gyoztes_pont + "-" +adatok[i].vesztes_pont + ";" + vesztescsap + ";" +adatok[i].nezoszam);
  107.             }
  108.             for (int i = 0; i < tempgy.Count; i++)
  109.             {
  110.                 sw.WriteLine(tempgy[i]);
  111.             }
  112.             //foreach (var e in adatok)
  113.             //{
  114.             //    if (!tempgy.Contains(e.gyoztes))
  115.             //    {
  116.             //        tempgy.Add(e.gyoztes);
  117.             //        gyoztesdb++;
  118.             //    }
  119.             //}
  120.             //List<string> tempv = new List<string>();
  121.             //foreach (var e in adatok)
  122.             //{
  123.             //    if (!tempv.Contains(e.vesztes))
  124.             //    {
  125.             //        tempv.Add(e.vesztes);
  126.             //        vesztesdb++;
  127.             //    }
  128.             //}
  129.             sw.Close();
  130.         }
  131.         static void Ex4()
  132.         {
  133.             Console.WriteLine($"4. feladat: Döntők száma: {adatok.Count}");
  134.         }
  135.         static void Ex5()
  136.         {
  137.             double avg = 0;
  138.             for (int i = 0; i < adatok.Count; i++)
  139.             {
  140.                 avg += (adatok[i].gyoztes_pont - adatok[i].vesztes_pont);
  141.             }
  142.             Console.WriteLine($"5. feladat: Átlagos pontkülönbség: {avg / adatok.Count:F1}");
  143.         }
  144.         static void Ex6()
  145.         {
  146.             int max = int.MinValue;
  147.             int maxindex = -1;
  148.             for (int i = 0; i < adatok.Count; i++)
  149.             {
  150.                 if (max < adatok[i].nezoszam)
  151.                 {
  152.                     max = adatok[i].nezoszam;
  153.                     maxindex = i;
  154.                 }
  155.             }
  156.             RomaiSorszam arab = new RomaiSorszam(adatok[maxindex].SorSz);
  157.             for (int i = 0; i < adatok.Count; i++)
  158.             {
  159.                 if (maxindex == i)
  160.                 {
  161.                     Console.WriteLine($"6. feladat: Legmagsabb nézőszám a döntők során: " +
  162.                         $"\n\tSorszám (dátum): {arab.ArabSsz} ({adatok[i].datum})\n\t" +
  163.                         $"Győztes csapat: {adatok[i].gyoztes}, szerzett pontok: {adatok[i].gyoztes_pont}\n\t" +
  164.                         $"Vesztes csapat: {adatok[i].vesztes}, szerzett pontok: {adatok[i].vesztes_pont}\n\t" +
  165.                         $"Helyszín: {adatok[i].helyszin}\n\tVáros, állam: {adatok[i].varosallam}\n\tNézőszám: {max}");
  166.                 }
  167.             }
  168.         }
  169.         static void Ex7()
  170.         {
  171.             //StreamWriter sw = new StreamWriter("SuperBowlNew.txt");
  172.             //sw.WriteLine(fejlec);
  173.             //List<string> tempgy = new List<string>();
  174.             //int gyoztesdb = 0;
  175.             //int vesztesdb = 0;
  176.             //for (int i = 0; i < adatok.Count; i++)
  177.             //{
  178.             //    for (int j = 0; j < tempgy.Count; j++)
  179.             //    {
  180.             //        if (tempgy[j].Contains(adatok[i].gyoztes))
  181.             //        {
  182.             //            gyoztesdb++;
  183.             //        }
  184.             //        if (tempgy[j].Contains(adatok[i].vesztes))
  185.             //        {
  186.             //            vesztesdb++;
  187.             //        }
  188.             //        string gyoztescsap = adatok[i].gyoztes + "(" + gyoztesdb.ToString() + ")";
  189.             //        string vesztescsap = adatok[i].vesztes + "(" + vesztesdb.ToString() + ")";
  190.             //        tempgy.Add(adatok[i].SorSz + ";" + adatok[i].datum +
  191.             //            ";" + gyoztescsap + ";" + adatok[i].gyoztes_pont + "-" +
  192.             //            adatok[i].vesztes_pont + ";" + adatok[i].vesztes + ";" +
  193.             //            adatok[i].nezoszam);
  194.             //    }
  195.             //}
  196.             //foreach (var e in tempgy)
  197.             //{
  198.             //    sw.WriteLine(e);
  199.             //}
  200.             ////foreach (var e in adatok)
  201.             ////{
  202.             ////    if (!tempgy.Contains(e.gyoztes))
  203.             ////    {
  204.             ////        tempgy.Add(e.gyoztes);
  205.             ////        gyoztesdb++;
  206.             ////    }
  207.             ////}
  208.             ////List<string> tempv = new List<string>();
  209.             ////foreach (var e in adatok)
  210.             ////{
  211.             ////    if (!tempv.Contains(e.vesztes))
  212.             ////    {
  213.             ////        tempv.Add(e.vesztes);
  214.             ////        vesztesdb++;
  215.             ////    }
  216.             ////}
  217.             //sw.Close();
  218.         }
  219.  
  220.         static void Main(string[] args)
  221.         {
  222.             Ex2();
  223.             Ex4();
  224.             Ex5();
  225.             Ex6();
  226.             Ex7();
  227.             Console.ReadKey();
  228.         }
  229.     }
  230. }
  231.  
Advertisement
Add Comment
Please, Sign In to add comment