【2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest A】【模拟 STL-map】Email Aliases 不同邮箱的数量

来源:互联网 发布:javascript面向对象 编辑:程序博客网 时间:2024/06/05 07:55

A. Email Aliases
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Polycarp has quite recently learned about email aliases. Of course, he used to suspect that the case of the letters doesn't matter in email addresses. He also learned that a popular mail server in Berland bmail.com ignores dots (characters '.') and all the part of an address from the first character "plus" ('+') to character "at" ('@') in a login part of email addresses.

Formally, any email address in this problem will look like "login@domain", where:

  • a "login" is a non-empty sequence of lowercase and uppercase letters, dots ('.') and pluses ('+'), which starts from a letter;
  • a "domain" is a non-empty sequence of lowercase and uppercase letters and dots, at that the dots split the sequences into non-empty words, consisting only from letters (that is, the "domain" starts from a letter, ends with a letter and doesn't contain two or more consecutive dots).

When you compare the addresses, the case of the characters isn't taken into consideration. Besides, when comparing the bmail.comaddresses, servers ignore the dots in the login and all characters from the first character "plus" ('+') to character "at" ('@') in login part of an email address.

For example, addresses saratov@example.com and SaratoV@Example.Com correspond to the same account. Similarly, addresses ACM.ICPC.@bmail.com and A.cmIcpc@Bmail.Com also correspond to the same account (the important thing here is that the domains of these addresses are bmail.com). The next example illustrates the use of character '+' in email address aliases: addresses polycarp+contest@BMAIL.COM, Polycarp@bmail.com and polycarp++acm+icpc@Bmail.Com also correspond to the same account on the server bmail.com. However, addresses a@bmail.com.ru and a+b@bmail.com.ru are not equivalent, because '+' is a special character only for bmail.com addresses.

Polycarp has thousands of records in his address book. Until today, he sincerely thought that that's exactly the number of people around the world that he is communicating to. Now he understands that not always distinct records in the address book represent distinct people.

Help Polycarp bring his notes in order by merging equivalent addresses into groups.

Input

The first line of the input contains a positive integer n (1 ≤ n ≤ 2·104) — the number of email addresses in Polycarp's address book.

The following n lines contain the email addresses, one per line. It is guaranteed that all of them are correct. All the given lines are distinct. The lengths of the addresses are from 3 to 100, inclusive.

Output

Print the number of groups k and then in k lines print the description of every group.

In the i-th line print the number of addresses in the group and all addresses that belong to the i-th group, separated by a space. It is allowed to print the groups and addresses in each group in any order.

Print the email addresses exactly as they were given in the input. Each address should go to exactly one group.

Sample test(s)
input
6ICPC.@bmail.comp+con+test@BMAIL.COMP@bmail.coma@bmail.com.ruI.cpc@Bmail.Coma+b@bmail.com.ru
output
42 ICPC.@bmail.com I.cpc@Bmail.Com 2 p+con+test@BMAIL.COM P@bmail.com 1 a@bmail.com.ru 1 a+b@bmail.com.ru 


#include<stdio.h>#include<iostream>#include<string.h>#include<string>#include<ctype.h>#include<vector>#include<map>using namespace std;const int N=2e4+10;char bmail[]={"bmail.com"};char s[105],S[105];map<string,int>mop;map<string,int>::iterator it;int n;int num[N];vector<string>a[N];int main(){    while(~scanf("%d",&n))    {        mop.clear();        int id=0;        for(int i=1;i<=n;i++)        {            scanf("%s",s);            strcpy(S,s);//转小写,记域名位置            int st;            for(int j=0;s[j];j++)            {                s[j]=tolower(s[j]);                if(s[j]=='@')st=j;            }//如果是bmail要做特殊转化            if(strcmp(s+st+1,bmail)==0)            {                int l=0;                for(int j=0;j<st;j++)                {                    if(s[j]=='.')continue;                    if(s[j]=='+')break;                    s[l++]=s[j];                }for(int j=st;s[j];j++)s[l++]=s[j];                s[l]=0;            }//存进map中            if(mop.find(s)==mop.end())mop[s]=++id;            int o=mop[s];            ++num[o];            a[o].push_back(S);        }        printf("%d\n",id);        for(int i=1;i<=id;i++)        {            cout<<num[i];            for(int j=0;j<a[i].size();j++)cout<<" "<<a[i][j];            puts("");            num[i]=0;            a[i].clear();        }    }    return 0;}/*【trick&&吐槽】我竟然没有输出不同邮箱的个数,导致WA一发,以后可不能这么粗心了!【题意】对于所有的邮箱,都是由login@domain这样的形式构成,而且字符都是不区分大小写的。我们有一种特殊类型的邮箱——@bmail.com,这种邮箱除了不区分大小写外——1,'@'之前的'.',有等同于无2,'@'之前的第一个'+'之后的字符可以忽略不计然后其他字符相同的被认定为邮箱相同。现在给你n(2e4)个邮箱,让你输出每个邮箱出现的次数与所有这个邮箱的原始串。【类型】map【分析】1,因为不分带小写,所以我们可以强制把字符串都转化为小写。2,然后要检测域名是否为@bmail.com,如果是,则忽略所有'.',然后再忽略第一个'+'之后的用户名然后这个邮箱再丢到map中,用来映射一个编号。这个编号对应着(频度,各个原始串)。【时间复杂度&&优化】O(nlogn)*/


3 0
原创粉丝点击