Advertisement
Guest User

Untitled

a guest
Jun 1st, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Reflection;
  4. using System.Collections.Generic;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class PizzaTime
  8. {
  9.     public static void Main()
  10.     {
  11.         MethodInfo[] methods = typeof(Pizza).GetMethods();
  12.         bool containsMethod = methods.Any(m => m.ReturnType.Name.Contains("SortedDictionary"));
  13.         if (!containsMethod)
  14.         {
  15.             throw new Exception();
  16.         }
  17.  
  18.         var input = Console.ReadLine().Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
  19.         var pizzas = new Pizza();
  20.         pizzas.PizzaMethod(input);
  21.     }
  22. }
  23.  
  24.  
  25.  
  26. public class Pizza
  27. {
  28.     public string name;
  29.     public long group;
  30.  
  31.     public SortedDictionary<int, List<string>> PizzaMethod(params string[] names)
  32.     {
  33.         var pizzas = new SortedDictionary<int, List<string>>();
  34.  
  35.         foreach (var pizza in names)
  36.         {
  37.             Match match = Regex.Match(pizza, @"([0-9]+)(.+)");
  38.             int currentGroup = int.Parse(match.Groups[1].Value);
  39.             string name = match.Groups[2].Value;
  40.  
  41.             if (!pizzas.ContainsKey(currentGroup))
  42.             {
  43.                 pizzas[currentGroup] = new List<string>();
  44.             }
  45.             pizzas[currentGroup].Add(name);
  46.         }
  47.  
  48.         foreach (var pizza in pizzas)
  49.         {
  50.             Console.WriteLine($"{pizza.Key} - {string.Join(", ", pizza.Value)}");
  51.         }
  52.  
  53.         return pizzas;
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement