Advertisement
simonradev

ASd

Jun 20th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. class Program
  8. {
  9.     public static Regex singleMethodInitialization = new Regex(@"(?<=static)\s+.*?\s+([A-Za-z][A-Za-z0-9]+)(.*?)(static|$)");
  10.     public static Regex singleMethodCall = new Regex("([a-zA-Z]*[A-Z]{1}[a-zA-Z]*)\\s*\\(");
  11.     public static Dictionary<string, List<string>> storage = new Dictionary<string, List<string>>();
  12.  
  13.     static void Main()
  14.     {
  15.         int n = int.Parse(Console.ReadLine());
  16.         StringBuilder stringBuilder = new StringBuilder();
  17.  
  18.         for (int i = 0; i < n; i++)
  19.         {
  20.             string input = Console.ReadLine();
  21.             stringBuilder.Append(input);
  22.         }
  23.  
  24.         string text = stringBuilder.ToString();
  25.  
  26.         if (!singleMethodInitialization.IsMatch(text))
  27.         {
  28.             return;
  29.         }
  30.  
  31.         var matches = singleMethodInitialization.Matches(text);
  32.  
  33.         foreach (Match method in matches)
  34.         {
  35.             string parentPethod = method.Groups[1].ToString();
  36.             if (!storage.ContainsKey(parentPethod))
  37.             {
  38.                 storage[parentPethod] = new List<string>();
  39.             }
  40.  
  41.             string methodBody = method.Groups[2].ToString();
  42.  
  43.             foreach (Match methodCall in singleMethodCall.Matches(methodBody))
  44.             {
  45.                 storage[parentPethod].Add(methodCall.Groups[1].ToString());
  46.             }
  47.         }
  48.         Print();
  49.     }
  50.  
  51.     public static void Print()
  52.     {
  53.         foreach (var parentPethod in storage.OrderBy(x => -x.Value.Count).ThenBy(x => x.Key))
  54.         {
  55.             var methodCalls = parentPethod.Value.OrderBy(x => x).ToList();
  56.             if (methodCalls.Count == 0)
  57.             {
  58.                 Console.WriteLine($"{parentPethod.Key} -> None");
  59.             }
  60.             else
  61.             {
  62.                 Console.WriteLine($"{parentPethod.Key} -> {parentPethod.Value.Count} -> {string.Join(", ", methodCalls)}");
  63.             }
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement