Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace EasterEggs
- {
- class Program
- {
- static void Main(string[] args)
- {
- int volume = int.Parse(Console.ReadLine());
- int red = 0;
- int orange = 0;
- int blue = 0;
- int green = 0;
- int max = 0;
- string maxColor = "";
- for (int i = 0; i < volume; i++)
- {
- string color = Console.ReadLine();
- switch (color)
- {
- case "red":
- red++;
- break;
- case "orange":
- orange++;
- break;
- case "blue":
- blue++;
- break;
- case "green":
- green++;
- break;
- }
- }
- if (red > orange && red > blue && red > green)
- {
- max = red;
- maxColor = "red";
- }
- else if (orange > blue && orange > green && orange > red)
- {
- max = orange;
- maxColor = "orange";
- }
- else if (blue > green && blue > red && blue > orange)
- {
- max = blue;
- maxColor = "blue";
- }
- else
- {
- max = green;
- maxColor = "green";
- }
- Console.WriteLine($"Red eggs: {red}");
- Console.WriteLine($"Orange eggs: {orange}");
- Console.WriteLine($"Blue eggs: {blue}");
- Console.WriteLine($"Green eggs: {green}");
- Console.WriteLine($"Max eggs: {max} -> {maxColor}");
- }
- }
- }
- РЕШЕНИЕ С DICTIONARY & LINQ:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace EasterEggs
- {
- class Program
- {
- static void Main(string[] args)
- {
- var eggColor = new Dictionary<string, int> { { "red", 0 }, { "orange", 0 }, { "blue", 0 }, { "green", 0 } };
- int volume = int.Parse(Console.ReadLine());
- for (int i = 0; i < volume; i++)
- {
- string color = Console.ReadLine();
- if (eggColor.ContainsKey(color))
- {
- eggColor[color]++;
- }
- }
- Console.WriteLine($"Red eggs: {eggColor["red"]}");
- Console.WriteLine($"Orange eggs: {eggColor["orange"]}");
- Console.WriteLine($"Blue eggs: {eggColor["blue"]}");
- Console.WriteLine($"Green eggs: {eggColor["green"]}");
- Console.WriteLine($"Max eggs: {eggColor.Values.Max()} -> {eggColor.OrderByDescending(x => x.Value).First().Key}");
- }
- }
- }
Add Comment
Please, Sign In to add comment