string+map+vector 乱搞就可以,反正n是10^4,理论复杂度是nlogn,所以肯定不会T的(好flag
大概就是先忽视大小写,然后根据域名是不是bmail.com,用户名有两种识别方法,然后统计每个用户名有多少个,分别是哪些就行
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;
#define ll long long
#define maxn 20005
char s0[maxn][105];
vector<int> num[maxn];
map<pair<string, string>, int> dict;
map<pair<string, string>, int>::iterator itor;
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i)
{
scanf("%s", s0[i]);
}
int pos = 0;
string login = "";
string domain = "";
//char login1[105], domain1[105];
for (int i = 0; i < n; ++i)
{
bool at = false;
login = "";
domain = "";
for (int j = 0; s0[i][j] != 0; ++j)
{
if (s0[i][j] == '@')
{
at = true;
continue;
}
if (at)
{
if (s0[i][j] >= 'A'&&s0[i][j] <= 'Z')
domain = domain + (char)(s0[i][j] - 'A' + 'a');
else
domain = domain + s0[i][j];
}
else
{
if (s0[i][j] >= 'A'&&s0[i][j] <= 'Z')
login = login + (char)(s0[i][j] - 'A' + 'a');
else
login = login + s0[i][j];
}
}
if (domain == "bmail.com")
{
string tmp = "";
for (unsigned int j = 0; j < login.length(); ++j)
{
if (login[j] == '.')
continue;
if (login[j] == '+')
break;
tmp = tmp + login[j];
}
login = tmp;
}
itor = dict.find(make_pair(login, domain));
if (itor == dict.end())
{
dict[make_pair(login, domain)] = pos;
num[pos].push_back(i);
++pos;
}
else
{
num[itor->second].push_back(i);
}
}
printf("%d\n", pos);
for (int i = 0; i < pos; ++i)
{
printf("%d ", num[i].size());
for (unsigned int j = 0; j < num[i].size(); ++j)
printf("%s ", s0[num[i][j]]);
printf("\n");
}
//system("pause");
//while (1);
return 0;
}