Advertisement
Guest User

Untitled

a guest
May 10th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. class Program
  8. {
  9.     static void Main()
  10.     {
  11.         string command = Console.ReadLine();
  12.         Dictionary<string, List<string>> dict = new Dictionary<string, List<string>>();
  13.  
  14.         while (command != "exit")
  15.         {
  16.             List<string> currentLine = command
  17.                 .Split(new char[] { '.', '(', ')' }, StringSplitOptions.RemoveEmptyEntries)
  18.                 .ToList();
  19.  
  20.             if (currentLine.Count == 1)
  21.             {
  22.                 int number;
  23.                 bool isDigit = int.TryParse(currentLine[0], out number);
  24.  
  25.                 if (isDigit)
  26.                 {
  27.                     foreach (var collection in dict.OrderByDescending(x => x.Value.Count))
  28.                     {
  29.                         List<string> selected = dict[collection.Key].OrderBy(x => x.Length)
  30.                             .ToList();
  31.  
  32.                         for (int i = 0; i < Math.Min(selected.Count, number); i++)
  33.                         {
  34.                             Console.WriteLine($"* {selected[i]}");
  35.                         }
  36.                         break;
  37.                     }
  38.                 }
  39.                 else
  40.                 {
  41.                     string collection = currentLine[0];
  42.  
  43.                     if (dict.ContainsKey(collection))
  44.                     {
  45.                         foreach (var method in dict[collection].OrderByDescending(x => x.Length).ThenByDescending(x => x.Distinct().Count()))
  46.                         {
  47.                             Console.WriteLine($"* {method}");
  48.                         }
  49.                     }
  50.                 }
  51.             }
  52.             else
  53.             {
  54.                 string collection = currentLine[0];
  55.  
  56.                 if (!dict.ContainsKey(collection))
  57.                 {
  58.                     dict.Add(collection, new List<string>());
  59.                 }
  60.                 dict[collection].AddRange(currentLine.Skip(1).Distinct());
  61.  
  62.             }
  63.  
  64.             command = Console.ReadLine();
  65.         }
  66.  
  67.         string[] lastCommand = Console.ReadLine().Split();
  68.  
  69.         string methodName = lastCommand[0];
  70.         string type = lastCommand[1];
  71.  
  72.         if (type == "collection")
  73.         {
  74.             foreach (var collection in dict.Where(x => x.Value.Contains(methodName)).OrderByDescending(x => x.Value.Count()).ThenByDescending(x => x.Value.Min(y => y.Length)))
  75.             {
  76.                 Console.WriteLine($"{collection.Key}");
  77.             }
  78.         }
  79.         else if(type == "all")
  80.         {
  81.             foreach (var collection in dict.Where(x => x.Value.Contains(methodName)).OrderByDescending(x => x.Value.Count()).ThenByDescending(x => x.Value.Min(y => y.Length)))
  82.             {
  83.                 Console.WriteLine($"{collection.Key}");
  84.  
  85.                 foreach (var method in collection.Value.OrderByDescending(x => x.Length))
  86.                 {
  87.                     Console.WriteLine($"* {method}");
  88.                 }
  89.             }
  90.         }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement