Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Reflection;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- public class PizzaTime
- {
- public static void Main()
- {
- MethodInfo[] methods = typeof(Pizza).GetMethods();
- bool containsMethod = methods.Any(m => m.ReturnType.Name.Contains("SortedDictionary"));
- if (!containsMethod)
- {
- throw new Exception();
- }
- var input = Console.ReadLine().Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
- var pizzas = new Pizza();
- pizzas.PizzaMethod(input);
- }
- }
- public class Pizza
- {
- public string name;
- public long group;
- public SortedDictionary<int, List<string>> PizzaMethod(params string[] names)
- {
- var pizzas = new SortedDictionary<int, List<string>>();
- foreach (var pizza in names)
- {
- Match match = Regex.Match(pizza, @"([0-9]+)(.+)");
- int currentGroup = int.Parse(match.Groups[1].Value);
- string name = match.Groups[2].Value;
- if (!pizzas.ContainsKey(currentGroup))
- {
- pizzas[currentGroup] = new List<string>();
- }
- pizzas[currentGroup].Add(name);
- }
- foreach (var pizza in pizzas)
- {
- Console.WriteLine($"{pizza.Key} - {string.Join(", ", pizza.Value)}");
- }
- return pizzas;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement