CodeForces 589A -- A. Email Aliases (字符串水题 STL)

来源:互联网 发布:python ftp 下载文件 编辑:程序博客网 时间:2024/06/16 15:06
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 



大体题意:

告诉你n 个邮箱名称,求出不同邮箱种类的个数,并输出不同种类邮箱。

思路:

根据题意:

首先把输入的邮箱名字全部转换为小写。

邮箱是bmail.com的比较特别,他是根据第一个加号之前进行判别,并忽略点(dot),来进行分类!

其余的邮箱则是全部来作为依据!

直接建立一个map<string,int> 来判别有没有存在就好了,然后给种类一个id 放到vector 即可!

详细见代码:

#include<bits/stdc++.h>using namespace std;const int maxn = 20000 + 10;const int inf = 0x3f3f3f3f;const double eps = 1e-8;const double pi = acos(-1.0);map<string,int>mp;int id = 0;int a[maxn];int vis[maxn];char s[maxn][108];char s2[maxn][108];char code[107];vector<string>v[maxn];int main(){    int n;    scanf("%d",&n);    for (int i = 0; i < n; ++i){        scanf("%s",s2[i]);        strcpy(s[i],s2[i]);        for (int j = 0; s[i][j] != 0; ++j)s[i][j] = tolower(s[i][j]);    }    for (int i = 0; i < n; ++i){        int pat = 0;        for (;s[i][pat]!='@';++pat);        strcpy(code,s[i]);        if (strcmp(s[i]+pat+1,"bmail.com") == 0){            int dot = -1;            for (int j = 0; j < pat; ++j){                if (s[i][j] == '+'){                    dot = j;                    break;                }            }            int cnt = 0;            for (int j = 0; j < (dot == -1 ? pat : dot); ++j){                if (s[i][j] == '.')continue;                code[cnt++] = s[i][j];            }            code[cnt] = 0;        }        if (!mp.count(code)){            mp[code] = id;            v[id].push_back(s2[i]);            id++;        }        else{            v[mp[code]].push_back(s2[i]);        }    }    printf("%d\n",id);    for (int i = 0; i < id; ++i){        int len = v[i].size();        printf("%d",len);        for (int j = 0; j < len ; ++j)printf(" %s",v[i][j].c_str());        puts("");    }    return 0;}



0 0
原创粉丝点击