I have a txt file with infos about some mobile phones.
Type;Size;Color;New-OrUsed;Warrantee(month);Price(HUF) iPhone SE;64;Gold;New;0;95000 iPhone 6S;64;Silver;New;3;130000 iPhone 5S;16;Black;New;5;60000 iPhone 5S;32;Gold;New;6;75000 iPhone 5S;32;RoseGold;New;8;66500 iPhone 7;32;Black;Used;10;135000 iPhone X;256;Silver;New;12;400000 iPhone 6S;128;Silver;New;3;173000 iPhone 8;128;Gold;New;12;256000 iPhone 7;64;Red;Used;4;155000 iPhone 8 Plus;64;Silver;New;4;285000 iPhone 6S Plus;64;Black;Used;8;180000 iPhone 7 Plus;32;Red;Used;6;192000 I would like to list all of them, like below:
Type (Only once, whatever how many of them);How many does the text have of this type; how many color does the text have of this type
iPhone 5S;3;3 I could list the types with a hashset, but I have no idea how to count the different colors, and the number of the type.
My code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Collections; namespace nyilvantartas { class Program { struct adatok { public string tipus, szin, allapot; public int meret, garancia, ar; } static void Main(string[] args) { StreamReader f = new StreamReader("termekek.txt", Encoding.Default); HashSet<string> tipusok = new HashSet<string>(); List<int> hanyvan = new List<int>(); string[] hanyvann = new string[20]; string s; string[] ss = new string[4]; adatok[] adatok = new adatok[1000]; int db = 0; s = f.ReadLine(); while (!f.EndOfStream) { s = f.ReadLine(); ss = s.Split(';'); adatok[db].tipus = ss[0]; adatok[db].meret = int.Parse(ss[1]); adatok[db].szin = ss[2]; adatok[db].allapot = ss[3]; adatok[db].garancia = int.Parse(ss[4]); adatok[db].ar = int.Parse(ss[5]); db++; } f.Close(); int ezustar = 0, gari=0; double legolcsobb = 500000,legdragabb=0; for (int i = 0; i < db; i++) { tipusok.Add(adatok[i].tipus); if (adatok[i].szin=="Silver") { ezustar += adatok[i].ar; } if (adatok[i].ar>legdragabb) { legdragabb = adatok[i].ar; } if (adatok[i].ar<legolcsobb) { legolcsobb = adatok[i].ar; } gari += adatok[i].garancia; } legdragabb /= legolcsobb; gari /= db; string[] tipusokk = new string[13]; for (int i = 0; i < db; i++) { tipusok.Add(adatok[i].tipus); } for (int i = 0; i < db; i++) { hanyvann[i] = adatok[i].tipus; } Console.WriteLine("2.Feladat: {0} db iPhone található a listában.",+db); Console.WriteLine("3.Feladat: Az összes ezüst színű készülék {0} Ft-ba kerülne",+ezustar); Console.WriteLine("4.Feladat:"); foreach (var item in tipusok) { Console.WriteLine(item); } Console.WriteLine("5.Feladat: Átlagossan {0} hónap garanciát kapunk",gari); Console.WriteLine("6.Felaadat: {0}-szor kerül többe a legdrágább a legolcsóbbnál.",legdragabb); Console.ReadKey(); } } }