· 6 years ago · Sep 26, 2019, 05:58 PM
1#include <iostream>
2#include <vector>
3#include <algorithm>
4#include <cctype>
5#include <string>
6#include <cstring>
7
8
9using namespace std;
10
11string Remove(string& str, string charToRemove){
12 //string s = "Pineapple";
13 //char chars[] = "p";
14 for (unsigned int i = 0; i < charToRemove.size(); ++i)
15 {
16 str.erase(remove(str.begin(), str.end(), charToRemove[i]), str.end());
17 }
18
19 return str;
20}
21
22bool EndsWith (std::string const &fullString, std::string const &ending) {
23 if (fullString.length() >= ending.length()) {
24 return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending));
25 } else {
26 return false;
27 }
28}
29
30string ToLower(string& data){
31 std::transform(data.begin(), data.end(), data.begin(),
32 [](unsigned char c){ return std::tolower(c); });
33
34 return data;
35}
36
37string PlusReform(string& s){
38 return s.substr(0, s.find('+', 0));
39}
40
41class Group{
42public:
43 vector<string> mails;
44 bool isgmail;
45 string lower;
46
47 Group(string s)
48 {
49 mails = vector<string>();
50 mails.push_back(s);
51 lower = ToLower(s);
52
53 if (EndsWith(s, "@gmail.com")){
54 isgmail = true;
55 lower = lower.substr(0, lower.size() - 10);
56 lower = PlusReform(lower);
57 lower = Remove(lower, ".");
58 }
59 else{
60 lower = s;
61 }
62 }
63
64 bool addnew(string str){
65 str = ToLower(str);
66
67 bool endsGmail = EndsWith(str, "@gmail.com");
68
69 if (!endsGmail)
70 {
71 if (isgmail)
72 {
73 return false;
74 }
75
76 return lower == str;
77 }
78
79 if (!isgmail)
80 return false;
81
82 // deleting gmail in end
83 if (str.size() > 10){
84 str = str.substr(0, str.size() - 10);
85 }
86
87 // all before first +
88 str = PlusReform(str);
89
90 // deleted tochki
91 str = Remove(str, ".");
92
93 return lower == str;
94 }
95
96 void toString(){
97 cout << mails.size() << " ";
98
99 for (int j = 0; j < mails.size(); ++j){
100 cout << mails[j] << " ";
101 }
102
103 cout << "\n";
104 }
105};
106
107int main()
108{
109 bool skip;
110 int k;
111 string str;
112 cin >> k;
113
114 vector<Group> groups = vector<Group>();
115
116 for (int i = 0; i < k; i++)
117 {
118 skip = false;
119 cin >> str;
120
121 for (int j = 0; j < groups.size(); j++)
122 {
123 if (groups[j].addnew(str))
124 {
125 groups[j].mails.push_back(str);
126 skip = true;
127 break;
128 }
129 }
130
131 if (skip)
132 continue;
133
134 // reached code here if no equal group found
135 groups.push_back(Group(str));
136 }
137
138 // output
139 cout << groups.size() << "\n";
140 for (int i = 0; i < groups.size(); ++i)
141 {
142 groups[i].toString();
143 }
144
145 return 0;
146}