SHARE
TWEET

Untitled

boykopk Nov 29th, 2017 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. public class Email_Statistics
  7. {
  8.     public static void Main()
  9.     {
  10.         Dictionary<string, HashSet<string>> emails = new Dictionary<string, HashSet<string>>();
  11.  
  12.         int emailsCount = int.Parse(Console.ReadLine());
  13.  
  14.         for (int i = 0; i < emailsCount; i++)
  15.         {
  16.             string email = Console.ReadLine();
  17.  
  18.             string emailPattern = @"^(?<username>[a-zA-Z]{5,})@(?<domain>(?<mailServer>[a-z]{3,})(?<topDomain>\.com|\.bg|\.org))$";
  19.             Match match = Regex.Match(email, emailPattern);
  20.  
  21.             if (match.Success)
  22.             {
  23.                 string domain = match.Groups["domain"].Value;
  24.                 string username = match.Groups["username"].Value;
  25.  
  26.                 if (!emails.ContainsKey(domain))
  27.                 {
  28.                     emails[domain] = new HashSet<string>();
  29.                 }
  30.  
  31.                 if (!emails[domain].Contains(username))
  32.                 {
  33.                     emails[domain].Add(username);
  34.                 }
  35.             }
  36.         }
  37.  
  38.         foreach (KeyValuePair<string, HashSet<string>> email in emails.OrderByDescending(x => x.Value.Count))
  39.         {
  40.             string domain = email.Key;
  41.             HashSet<string> usernames = email.Value;
  42.  
  43.             Console.WriteLine($"{domain}:");
  44.  
  45.             foreach (string username in usernames)
  46.             {
  47.                 Console.WriteLine($"### {username}");
  48.             }
  49.         }
  50.     }
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top