· 6 years ago · Sep 26, 2019, 05:56 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 str = str.substr(0, str.size() - 10);
84
85 // all before first +
86 str = PlusReform(str);
87
88 // deleted tochki
89 str = Remove(str, ".");
90
91 return lower == str;
92 }
93
94 void toString(){
95 cout << mails.size() << " ";
96
97 for (int j = 0; j < mails.size(); ++j){
98 cout << mails[j] << " ";
99 }
100
101 cout << "\n";
102 }
103};
104
105int main()
106{
107 bool skip;
108 int k;
109 string str;
110 cin >> k;
111
112 vector<Group*> groups = vector<Group*>();
113
114 for (int i = 0; i < k; i++)
115 {
116 skip = false;
117 cin >> str;
118
119 for (int j = 0; j < groups.size(); j++)
120 {
121 if (groups[j]->addnew(str))
122 {
123 groups[j]->mails.push_back(str);
124 skip = true;
125 break;
126 }
127 }
128
129 if (skip)
130 continue;
131
132 // reached code here if no equal group found
133 groups.push_back(new Group(str));
134 }
135
136 // output
137 cout << groups.size() << "\n";
138 for (int i = 0; i < groups.size(); ++i)
139 {
140 groups[i]->toString();
141 }
142
143 return 0;
144}