Advertisement
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;
- class Program
- {
- static void Main()
- {
- string command = Console.ReadLine();
- Dictionary<string, List<string>> dict = new Dictionary<string, List<string>>();
- while (command != "exit")
- {
- List<string> currentLine = command
- .Split(new char[] { '.', '(', ')' }, StringSplitOptions.RemoveEmptyEntries)
- .ToList();
- if (currentLine.Count == 1)
- {
- int number;
- bool isDigit = int.TryParse(currentLine[0], out number);
- if (isDigit)
- {
- foreach (var collection in dict.OrderByDescending(x => x.Value.Count))
- {
- List<string> selected = dict[collection.Key].OrderBy(x => x.Length)
- .ToList();
- for (int i = 0; i < Math.Min(selected.Count, number); i++)
- {
- Console.WriteLine($"* {selected[i]}");
- }
- break;
- }
- }
- else
- {
- string collection = currentLine[0];
- if (dict.ContainsKey(collection))
- {
- foreach (var method in dict[collection].OrderByDescending(x => x.Length).ThenByDescending(x => x.Distinct().Count()))
- {
- Console.WriteLine($"* {method}");
- }
- }
- }
- }
- else
- {
- string collection = currentLine[0];
- if (!dict.ContainsKey(collection))
- {
- dict.Add(collection, new List<string>());
- }
- dict[collection].AddRange(currentLine.Skip(1).Distinct());
- }
- command = Console.ReadLine();
- }
- string[] lastCommand = Console.ReadLine().Split();
- string methodName = lastCommand[0];
- string type = lastCommand[1];
- if (type == "collection")
- {
- foreach (var collection in dict.Where(x => x.Value.Contains(methodName)).OrderByDescending(x => x.Value.Count()).ThenByDescending(x => x.Value.Min(y => y.Length)))
- {
- Console.WriteLine($"{collection.Key}");
- }
- }
- else if(type == "all")
- {
- foreach (var collection in dict.Where(x => x.Value.Contains(methodName)).OrderByDescending(x => x.Value.Count()).ThenByDescending(x => x.Value.Min(y => y.Length)))
- {
- Console.WriteLine($"{collection.Key}");
- foreach (var method in collection.Value.OrderByDescending(x => x.Length))
- {
- Console.WriteLine($"* {method}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement