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.Text.RegularExpressions;
- namespace _10b_Regular_Expressions_RegEx_Exercises
- {
- class Regular_Expressions_RegEx_Exercises
- {
- static void Main(string[] args)
- {
- int count = int.Parse(Console.ReadLine());
- Dictionary<string, List<string>> mailList = new Dictionary<string, List<string>>();
- for (int i = 0; i < count; i++)
- {
- string pattern = @"^(?<username>[a-zA-Z]{5,})@(?<domain>(?<mailServer>[a-z]{3,})(?<topDomain>\.com|\.bg|\.org))$";
- string mail = Console.ReadLine();
- Match match = Regex.Match(mail, pattern);
- if (match.Success)
- {
- string mailServer = match.Groups["domain"].Value;
- string user = match.Groups["username"].Value;
- if (!mailList.ContainsKey(mailServer))
- {
- mailList[mailServer] = new List<string>();
- }
- if (!mailList[mailServer].Contains(user))
- {
- mailList[mailServer].Add(user);
- }
- }
- }
- foreach (var item in mailList.OrderByDescending(x => x.Value.Count))
- {
- Console.WriteLine($"{item.Key}:");
- foreach (var item2 in item.Value)
- {
- Console.WriteLine($"### {item2}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment