· 9 years ago · Oct 03, 2016, 01:00 PM
1#include <iostream>
2#include <unordered_map>
3#include <string>
4#include <vector>
5#include <algorithm>
6
7using namespace std;
8
9int main() {
10 unordered_map<string, vector <string>> my_map;
11 int n;
12 cin >> n;
13 string str;
14
15 for (int i = 0; i < n; i++)
16 {
17 cin >> str;
18 string newstring = "";
19 string strorigin = str;
20 transform (str.begin(), str.end(), str.begin(), ::tolower);
21 int pos = str.find('@');
22 if (str.compare (pos, str.size() - pos, "@gmail.com"))
23 {
24 int qold = 0;
25 if (int plus = str.find('+') != string ::npos)
26 {
27 string e = "";
28 str.replace(str.begin()+plus, str.begin()+pos-1, e.begin(), e.end());
29 pos = str.find('@');
30 }
31 while (int q = str.find('.', qold+1) != string :: npos && q != pos)
32 {
33 newstring += str.substr(qold+1, q-qold-1);
34 qold = q;
35 }
36 }
37 if (my_map.find(newstring) == my_map.end())
38 {
39 my_map[newstring] = vector<string>();
40 }
41 my_map[newstring].push_back(strorigin);
42 }
43 cout << my_map.size() << endl;
44 for (const auto &item0 :my_map)
45 {
46 cout << item0.second.size();
47 for (int i = 0; i < item0.second.size(); i++)
48 {
49 cout << ' ' << item0.second[i];
50 }
51 cout << endl;
52 }
53 return 0;
54}