static void Main() { Gvozdikes gvozdiki = new Gvozdikes("Gvozdiki", 100); Roses roses = new Roses("Rose", 120); Tulpanes tulpanes = new Tulpanes("Tulpan", 80); Flower[] flowers = new Flower[3] { gvozdiki, roses, tulpanes }; Random rnd = new Random(); Buket buket = new Buket(); Console.WriteLine("Vvedite kolichestvo cvetkov v bukete"); int numberOfFlowers = 0; do { Console.Write("Kolichestvo = "); } while (!int.TryParse(Console.ReadLine(), out numberOfFlowers) || numberOfFlowers == 0); int FlowersLeft = 0; do { buket.AddFlowerToBuket(flowers[rnd.Next(0, 2)]); FlowersLeft++; } while (FlowersLeft < numberOfFlowers); Console.WriteLine(buket.ReturnBuket()); Console.ReadKey(); }
public static void Main() { List <Roses> roses = new List <Roses>(); string pattern = @"Grow\s<([A-Z]{1}[a-z]+)>\s<([A-z\d]+)>\s(\d+)(?!.)"; string input = Console.ReadLine(); while (input != "Icarus, Ignite!") { Regex regex = new Regex(pattern); Match match = regex.Match(input); if (match.Success) { string region = match.Groups[1].Value; string color = match.Groups[2].Value; long amount = long.Parse(match.Groups[3].Value); Roses rose = new Roses(); if (roses.Any(a => a.RegionName == region)) { int index = roses.FindIndex(a => a.RegionName == region); if (roses[index].ColorAndAmount.ContainsKey(color)) { roses[index].ColorAndAmount[color] += amount; } else { roses[index].ColorAndAmount[color] = amount; } } else { rose.RegionName = region; rose.ColorAndAmount[color] = amount; roses.Add(rose); } } input = Console.ReadLine(); } var result = roses.OrderByDescending(a => a.ColorAndAmount.Sum(k => k.Value)).ThenBy(a => a.RegionName); foreach (var rose in result) { Console.WriteLine(rose.RegionName); foreach (var property in rose.ColorAndAmount.OrderBy(r => r.Value).ThenBy(r => r.Key)) { Console.WriteLine($"*--{property.Key} | {property.Value}"); } } }
public static void AddRoses(Roses _modelRoses) { Roses._modelRoses.Add(_modelRoses); }
static void Yourchoice(int choice) { switch (choice) { case 1: Showbase(); break; case 2: Console.WriteLine("Что вы бы хотели купить(Выберите по индексу):"); Showbase(); short choiceToBuy = Convert.ToInt16(Console.ReadLine()); if (choiceToBuy == 1 || choiceToBuy == 2 || choiceToBuy == 3) { switch (choiceToBuy) { case 1: Kaktus.Buy(); break; case 2: Roses.Buy(); Roses.Pleusure(); break; case 3: Gladiolus.Buy(); Gladiolus.Pleusure(); break; } } break; case 3: { choiceToBuy = 1; while (choiceToBuy != 0) { Console.WriteLine("0-выход\n1-Добавить элементы в коллекцию\n2-Показать элементы в коллекции" + "\n3-Удаление элемента из коллекции\n4-Купить букет" + ""); choiceToBuy = Convert.ToInt16(Console.ReadLine()); if (choiceToBuy == 1 || choiceToBuy == 2 || choiceToBuy == 3 || choiceToBuy == 4) { switch (choiceToBuy) { case 1: MyCollection.Add(Kaktus, Roses, Gladiolus); break; case 2: MyCollection.Show(); break; case 3: MyCollection.Delete(); break; case 4: Console.WriteLine($"{Controller.Buy(MyCollection)} руб."); break; } } } } return; default: return; } }