Advertisement
simonradev

JediDreams

Jun 20th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.30 KB | None | 0 0
  1. namespace JediDreams
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.     using System.Text;
  7.     using System.Text.RegularExpressions;
  8.     using System.Threading.Tasks;
  9.    
  10.     public class StartUp
  11.     {
  12.         public static void Main()
  13.         {
  14.             Regex methodDeclaretion = new Regex(@"static\s+.*?\s+([a-zA-Z]*[A-Z]{1}[a-zA-Z]*)\s*\(");
  15.             Regex methodInvoke = new Regex(@"([a-zA-Z]*[A-Z]{1}[a-zA-Z]*)\s*\(");
  16.  
  17.             Dictionary<string, List<string>> methodCalls = new Dictionary<string, List<string>>();
  18.  
  19.             string lastMethodDeclared = default(string);
  20.  
  21.             int countOfInputLines = int.Parse(Console.ReadLine());
  22.             for (int currentInputLine = 0; currentInputLine < countOfInputLines; currentInputLine++)
  23.             {
  24.                 string inputLine = Console.ReadLine();
  25.  
  26.                 Match match = methodDeclaretion.Match(inputLine);
  27.                 MatchCollection allMatches = methodInvoke.Matches(inputLine);
  28.  
  29.                 if (match.Success)
  30.                 {
  31.                     lastMethodDeclared = match.Groups[1].Value;
  32.  
  33.                     if (!methodCalls.ContainsKey(lastMethodDeclared))
  34.                     {
  35.                         methodCalls[lastMethodDeclared] = new List<string>();
  36.                     }
  37.                 }
  38.                 else if (allMatches.Count != 0 && lastMethodDeclared != default(string))
  39.                 {
  40.                     foreach (Match currMatch in allMatches)
  41.                     {
  42.                         methodCalls[lastMethodDeclared].Add(currMatch.Groups[1].Value);
  43.                     }
  44.                 }
  45.             }
  46.  
  47.             StringBuilder result = new StringBuilder();
  48.             foreach (KeyValuePair<string, List<string>> kvp in methodCalls.OrderByDescending(mc => mc.Value.Count).ThenBy(n => n.Key))
  49.             {
  50.                 result.Append($"{kvp.Key} -> ");
  51.  
  52.                 if (kvp.Value.Count == 0)
  53.                 {
  54.                     result.AppendLine("None");
  55.                 }
  56.                 else
  57.                 {
  58.                     result.Append($"{kvp.Value.Count} -> ").AppendLine(string.Join(", ", kvp.Value.OrderBy(s => s)));
  59.                 }
  60.             }
  61.  
  62.             Console.Write(result);
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement