· 7 years ago · Apr 27, 2019, 06:06 PM
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Text.RegularExpressions;
6using System.Threading.Tasks;
7
8namespace ConsoleApp2
9{
10 class Program
11 {
12 static void Main(string[] args)
13 {
14 if (int.TryParse(Console.ReadLine(), out int emailsCount))
15 {
16 if (emailsCount >= 1 && emailsCount <= 20000)
17 {
18 string[] emails = new string[emailsCount];
19 for (int i = 0; i < emailsCount; i++)
20 {
21 emails[i] = Console.ReadLine();
22
23 Regex loginEx = new Regex(@"^[A-z][A-z\.\+0-9]*@(([A-z]*)(\.)([A-z]+))+$");
24 if (!loginEx.IsMatch(emails[i]))
25 {
26 Console.WriteLine("ÐÐ´Ñ€ÐµÑ Ð²Ð²ÐµÐ´ÐµÐ½ неверно");
27 i--;
28 continue;
29 }
30 }
31
32 // заполнили адреÑами
33
34 Dictionary<string, List<string>> equalGroups = new Dictionary<string, List<string>>();
35
36 for (int i = 0; i < emailsCount; i++)
37 {
38 string login = emails[i].Split('@')[0];
39 string loginView = login.ToLower();
40 string domain = emails[i].Split('@')[1];
41
42 if (domain.ToLower() == "gmail.com" )
43 {
44 loginView = loginView.Replace(".", "");
45 loginView = loginView.Split('+')[0];
46 }
47
48 string fullName = loginView + "@" + domain.ToLower();
49
50 if (equalGroups.ContainsKey(fullName))
51 {
52 equalGroups[fullName].Add(emails[i]);
53 }
54 else
55 {
56 equalGroups.Add(fullName, new List<string>() { emails[i] });
57 }
58 }
59
60 Console.WriteLine(equalGroups.Count);
61 for (int i = 0; i < equalGroups.Count; i++)
62 {
63 Console.Write(equalGroups.ElementAt(i).Value.Count + " ");
64
65 string res = "";
66 for (int j = 0; j < equalGroups.ElementAt(i).Value.Count; j++)
67 {
68 res += equalGroups.ElementAt(i).Value[j] + " ";
69 }
70 res.Trim();
71 Console.WriteLine(res);
72 }
73 }
74 }
75 }
76 }
77}