Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace LINQuistics
- {
- class LINQuistics
- {
- static void Main(string[] args)
- {
- var collections = new Dictionary<string, List<string>>();
- int t;
- while (true)
- {
- string[] input = Console.ReadLine()
- .Split(new string[] { ".", "()" }, StringSplitOptions.RemoveEmptyEntries);
- if (input[0] == "exit") { break; }
- string collection = input[0];
- if (input.Length > 1)
- {
- for (int i = 1; i < input.Length; i++)
- {
- string method = input[i];
- if (!collections.ContainsKey(collection))
- {
- collections.Add(collection, new List<string>());
- }
- if (!collections[collection].Contains(method))
- {
- collections[collection].Add(method);
- }
- }
- }
- if (input.Length == 1)
- {
- if (collections.ContainsKey(collection))
- {
- var methodsList = collections[collection]
- .OrderByDescending(m => m.Length).ThenByDescending(p => p.Distinct().Count()).ToList();
- for (int n = 0; n < methodsList.Count; n++)
- {
- Console.WriteLine("* {0}", methodsList[n]);
- }
- }
- if (int.TryParse(collection, out t))
- {
- foreach (var item in collections.OrderByDescending(p => p.Value.Count).Take(1))
- {
- foreach (var method in item.Value.OrderBy(p => p.Length).Take(t))
- {
- Console.WriteLine($"* {method}");
- }
- }
- }
- }
- }
- string[] finalInput = Console.ReadLine().Split(' ');
- string wantedMethod = finalInput[0];
- string wantedCollection = finalInput[1];
- if (wantedCollection == "collection")
- {
- foreach (var item in collections
- .OrderByDescending(m => m.Value.Count).ThenByDescending(m => m.Value.Min(s => s.Length)))
- {
- if (item.Value.Contains(wantedMethod))
- {
- Console.WriteLine(item.Key);
- }
- }
- }
- if (wantedCollection == "all")
- {
- foreach (var item in collections
- .OrderByDescending(m => m.Value.Count).ThenByDescending(m => m.Value.Min(s => s.Length)))
- {
- Console.WriteLine(item.Key);
- foreach (var method in item.Value.OrderByDescending(m => m.Length))
- {
- Console.WriteLine($"* {method}");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment