svetliovd

LINQuistics

Jul 17th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.42 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. namespace LINQuistics
  8. {
  9.     class LINQuistics
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var collections = new Dictionary<string, List<string>>();
  14.             int  t;
  15.             while (true)
  16.             {
  17.                 string[] input = Console.ReadLine()
  18.                     .Split(new string[] { ".", "()" }, StringSplitOptions.RemoveEmptyEntries);
  19.                 if (input[0] == "exit") { break; }
  20.                 string collection = input[0];
  21.                 if (input.Length > 1)
  22.                 {
  23.                     for (int i = 1; i < input.Length; i++)
  24.                     {
  25.                         string method = input[i];
  26.                         if (!collections.ContainsKey(collection))
  27.                         {
  28.                             collections.Add(collection, new List<string>());
  29.                         }
  30.                         if (!collections[collection].Contains(method))
  31.                         {
  32.                             collections[collection].Add(method);
  33.                         }      
  34.                     }
  35.                 }
  36.                 if (input.Length == 1)
  37.                 {
  38.                     if (collections.ContainsKey(collection))
  39.                     {
  40.                         var methodsList = collections[collection]
  41.                         .OrderByDescending(m => m.Length).ThenByDescending(p => p.Distinct().Count()).ToList();
  42.                        
  43.                             for (int n = 0; n < methodsList.Count; n++)
  44.                             {
  45.                                 Console.WriteLine("* {0}", methodsList[n]);
  46.                             }
  47.                     }
  48.                     if (int.TryParse(collection, out t))
  49.                     {
  50.                         foreach (var item in collections.OrderByDescending(p => p.Value.Count).Take(1))
  51.                         {
  52.                             foreach (var method in item.Value.OrderBy(p => p.Length).Take(t))
  53.                             {
  54.                                 Console.WriteLine($"* {method}");
  55.                             }
  56.                         }
  57.                     }
  58.                 }
  59.             }
  60.             string[] finalInput = Console.ReadLine().Split(' ');
  61.             string wantedMethod = finalInput[0];
  62.             string wantedCollection = finalInput[1];
  63.             if (wantedCollection == "collection")
  64.             {
  65.                 foreach (var item in collections
  66.                     .OrderByDescending(m => m.Value.Count).ThenByDescending(m => m.Value.Min(s => s.Length)))
  67.                 {
  68.                     if (item.Value.Contains(wantedMethod))
  69.                     {
  70.                         Console.WriteLine(item.Key);
  71.                     }
  72.                 }
  73.             }
  74.             if (wantedCollection == "all")
  75.             {
  76.                 foreach (var item in collections
  77.                     .OrderByDescending(m => m.Value.Count).ThenByDescending(m => m.Value.Min(s => s.Length)))
  78.                 {
  79.                     Console.WriteLine(item.Key);
  80.                     foreach (var method in item.Value.OrderByDescending(m => m.Length))
  81.                     {
  82.                         Console.WriteLine($"* {method}");
  83.                     }
  84.                 }
  85.             }
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment