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 SuperBowl
- {
- class RomaiSorszam
- {
- public string RomaiSsz { get; private set; }
- private static Dictionary<char, int> RomaiMap = new Dictionary<char, int>()
- {
- {'I', 1}, {'V', 5}, {'X', 10}, {'L', 50}, {'C', 100}, {'D', 500}, {'M', 1000}
- };
- public string ArabSsz
- {
- get
- {
- int ertek = 0;
- string romaiSzam = RomaiSsz.TrimEnd('.');
- for (int i = 0; i < romaiSzam.Length; i++)
- {
- if (i + 1 < romaiSzam.Length &&
- RomaiMap[romaiSzam[i]] < RomaiMap[romaiSzam[i + 1]])
- {
- ertek -= RomaiMap[romaiSzam[i]];
- }
- else
- {
- ertek += RomaiMap[romaiSzam[i]];
- }
- }
- return $"{ertek}.";
- }
- }
- public RomaiSorszam(string romaiSsz)
- {
- RomaiSsz = romaiSsz.ToUpper();
- }
- }
- class C_SuperBowl
- {
- public string SorSz, datum, gyoztes, vesztes, helyszin, varosallam;
- public int gyoztes_pont, vesztes_pont, nezoszam;
- public C_SuperBowl(string sor)
- {
- string[] egysor = sor.Split(';');
- SorSz = egysor[0];
- datum = egysor[1];
- gyoztes = egysor[2];
- gyoztes_pont = Convert.ToInt32(egysor[3].Split('-')[0]);
- vesztes_pont = Convert.ToInt32(egysor[3].Split('-')[1]);
- vesztes = egysor[4];
- helyszin = egysor[5];
- varosallam = egysor[6];
- nezoszam = Convert.ToInt32(egysor[7]);
- }
- }
- class SuperBowl
- {
- static List<C_SuperBowl> adatok = new List<C_SuperBowl>();
- static void Ex2()
- {
- StreamReader sr = new StreamReader("SuperBowl.txt");
- string fejlec=sr.ReadLine();
- while (!sr.EndOfStream)
- {
- adatok.Add(new C_SuperBowl(sr.ReadLine()));
- }
- sr.Close();
- //foreach (var e in adatok)
- //{
- // Console.WriteLine($"{e.gyoztes_pont}");
- //}
- StreamWriter sw = new StreamWriter("SuperBowlNew.txt");
- sw.WriteLine(fejlec);
- List<string> tempgy = new List<string>();
- int gyoztesdb = 0;
- int vesztesdb = 0;
- for (int i = 0; i < adatok.Count; i++)
- {
- for (int j = 0; j < tempgy.Count; j++)
- {
- if (tempgy[j].Contains(adatok[i].gyoztes))
- {
- gyoztesdb++;
- }
- if (tempgy[j].Contains(adatok[i].vesztes))
- {
- vesztesdb++;
- }
- }
- string gyoztescsap = adatok[i].gyoztes + "(" + gyoztesdb.ToString() + ")";
- string vesztescsap = adatok[i].vesztes + "(" + vesztesdb.ToString() + ")";
- tempgy.Add(adatok[i].SorSz + ";" + adatok[i].datum +";" + gyoztescsap + ";" + adatok[i].gyoztes_pont + "-" +adatok[i].vesztes_pont + ";" + vesztescsap + ";" +adatok[i].nezoszam);
- }
- for (int i = 0; i < tempgy.Count; i++)
- {
- sw.WriteLine(tempgy[i]);
- }
- //foreach (var e in adatok)
- //{
- // if (!tempgy.Contains(e.gyoztes))
- // {
- // tempgy.Add(e.gyoztes);
- // gyoztesdb++;
- // }
- //}
- //List<string> tempv = new List<string>();
- //foreach (var e in adatok)
- //{
- // if (!tempv.Contains(e.vesztes))
- // {
- // tempv.Add(e.vesztes);
- // vesztesdb++;
- // }
- //}
- sw.Close();
- }
- static void Ex4()
- {
- Console.WriteLine($"4. feladat: Döntők száma: {adatok.Count}");
- }
- static void Ex5()
- {
- double avg = 0;
- for (int i = 0; i < adatok.Count; i++)
- {
- avg += (adatok[i].gyoztes_pont - adatok[i].vesztes_pont);
- }
- Console.WriteLine($"5. feladat: Átlagos pontkülönbség: {avg / adatok.Count:F1}");
- }
- static void Ex6()
- {
- int max = int.MinValue;
- int maxindex = -1;
- for (int i = 0; i < adatok.Count; i++)
- {
- if (max < adatok[i].nezoszam)
- {
- max = adatok[i].nezoszam;
- maxindex = i;
- }
- }
- RomaiSorszam arab = new RomaiSorszam(adatok[maxindex].SorSz);
- for (int i = 0; i < adatok.Count; i++)
- {
- if (maxindex == i)
- {
- Console.WriteLine($"6. feladat: Legmagsabb nézőszám a döntők során: " +
- $"\n\tSorszám (dátum): {arab.ArabSsz} ({adatok[i].datum})\n\t" +
- $"Győztes csapat: {adatok[i].gyoztes}, szerzett pontok: {adatok[i].gyoztes_pont}\n\t" +
- $"Vesztes csapat: {adatok[i].vesztes}, szerzett pontok: {adatok[i].vesztes_pont}\n\t" +
- $"Helyszín: {adatok[i].helyszin}\n\tVáros, állam: {adatok[i].varosallam}\n\tNézőszám: {max}");
- }
- }
- }
- static void Ex7()
- {
- //StreamWriter sw = new StreamWriter("SuperBowlNew.txt");
- //sw.WriteLine(fejlec);
- //List<string> tempgy = new List<string>();
- //int gyoztesdb = 0;
- //int vesztesdb = 0;
- //for (int i = 0; i < adatok.Count; i++)
- //{
- // for (int j = 0; j < tempgy.Count; j++)
- // {
- // if (tempgy[j].Contains(adatok[i].gyoztes))
- // {
- // gyoztesdb++;
- // }
- // if (tempgy[j].Contains(adatok[i].vesztes))
- // {
- // vesztesdb++;
- // }
- // string gyoztescsap = adatok[i].gyoztes + "(" + gyoztesdb.ToString() + ")";
- // string vesztescsap = adatok[i].vesztes + "(" + vesztesdb.ToString() + ")";
- // tempgy.Add(adatok[i].SorSz + ";" + adatok[i].datum +
- // ";" + gyoztescsap + ";" + adatok[i].gyoztes_pont + "-" +
- // adatok[i].vesztes_pont + ";" + adatok[i].vesztes + ";" +
- // adatok[i].nezoszam);
- // }
- //}
- //foreach (var e in tempgy)
- //{
- // sw.WriteLine(e);
- //}
- ////foreach (var e in adatok)
- ////{
- //// if (!tempgy.Contains(e.gyoztes))
- //// {
- //// tempgy.Add(e.gyoztes);
- //// gyoztesdb++;
- //// }
- ////}
- ////List<string> tempv = new List<string>();
- ////foreach (var e in adatok)
- ////{
- //// if (!tempv.Contains(e.vesztes))
- //// {
- //// tempv.Add(e.vesztes);
- //// vesztesdb++;
- //// }
- ////}
- //sw.Close();
- }
- static void Main(string[] args)
- {
- Ex2();
- Ex4();
- Ex5();
- Ex6();
- Ex7();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment