· 6 years ago · Sep 26, 2019, 04:46 PM
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6
7namespace Task_2
8{
9 public class Group
10 {
11 public List<string> Mails { get; set; }
12
13 public bool IsEqual(string str)
14 {
15 var same = Mails[0].ToLower();
16 str = str.ToLower();
17
18 if (!str.EndsWith("@gmail.com"))
19 {
20 return same.Equals(str);
21 }
22
23 /*
24 // deleted gmail.com
25 if (same.Length > 10)
26 same = same.Substring(0, same.Length - 10);
27 if (str.Length > 10)
28 str = str.Substring(0, str.Length - 10);
29 */
30
31 // all before first +
32 same = same.Split('+')[0];
33 str = str.Split('+')[0];
34
35 // deleted tochki
36 same = same.Replace(".", "");
37 str = str.Replace(".", "");
38
39 return same.Equals(str);
40 }
41
42 public override string ToString()
43 {
44 string str = $"{Mails.Count} ";
45
46 foreach (var s in Mails)
47 {
48 str += s + " ";
49 }
50
51 return str;
52 }
53 }
54
55 class Program
56 {
57 static void Main(string[] args)
58 {
59 bool skip;
60 int k;
61 string str;
62 k = int.Parse(Console.ReadLine());
63
64 List<Group> groups = new List<Group>();
65
66 for (int i = 0; i < k; i++)
67 {
68 skip = false;
69 str = Console.ReadLine();
70
71 foreach (var group in groups)
72 {
73 if (group.IsEqual(str))
74 {
75 group.Mails.Add(str);
76 skip = true;
77 break;
78 }
79 }
80
81 if (skip)
82 continue;
83
84 // reached code here if no equal group found
85 groups.Add(new Group()
86 {
87 Mails = new List<string>() { str }
88 });
89 }
90
91 // output
92 Console.WriteLine(groups.Count);
93 foreach (var group in groups)
94 {
95 Console.WriteLine(group.ToString());
96 }
97
98 Console.ReadLine();
99 }
100 }
101}