Advertisement
Stan08

MoreRegex/6.EmailStatistics_dictionary

Jun 25th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Linq;
  4. using System.Globalization;
  5. using System.Collections.Generic;
  6. using System.Text;
  7.  
  8. public class Example
  9.  
  10. {
  11. public static void Main(string[] args)
  12.  
  13. {
  14. int n = int.Parse(Console.ReadLine());
  15.  
  16. Dictionary<string, List<string>> valid = new Dictionary<string, List<string>>();
  17.  
  18. Regex r = new Regex(@"^[A-Za-z]{5,}@[a-z]{3,}(\.com|\.bg|\.org)$");
  19.  
  20. for (int i = 0; i < n; i++)
  21. {
  22.  
  23. string input = Console.ReadLine();
  24. if (!r.Match(input).Success)
  25. {
  26. continue;
  27. }
  28. string[] splt = input.Split('@').ToArray();
  29. if (valid.ContainsKey(splt[1]))
  30. {
  31. if (valid[splt[1]].Any(t => t == splt[0]))
  32. {
  33. continue;
  34. }
  35. valid[splt[1]].Add(splt[0]);
  36. }
  37. else
  38. {
  39. valid.Add(splt[1], new List<string>() { splt[0] });
  40. }
  41. }
  42.  
  43. foreach (var domain in valid.OrderByDescending(t => t.Value.Count))
  44. {
  45. Console.WriteLine($"{domain.Key}:");
  46. foreach (var user in domain.Value)
  47. {
  48. Console.WriteLine($"### {user}");
  49. }
  50. }
  51.  
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement