codefroces 589A

time limit per test
seconds
memory limit per test
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
ICPC.@bmail.com
p+con+test@BMAIL.COM
P@bmail.com
a@bmail.com.ru
I.cpc@Bmail.Com
a+b@bmail.com.ru
output
2 ICPC.@bmail.com I.cpc@Bmail.Com
p+con+test@BMAIL.COM P@bmail.com
a@bmail.com.ru
a+b@bmail.com.ru

 

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
#include <map>
#define isupc(x) ((x) >= 65 && (x) <= 90) ? 1 : 0
using namespace std;
const int N = 2e4 + 10;
typedef pair<int, int> pii;
int n, c;
char S[N][105], s[105], t[105];
map<string, pii> m;
map<string, pii> ::reverse_iterator it, at;
vector<int> G[N];
string str;
void go(char x) {
    if(isupc(x)) t[c++] = x + 32;
    else t[c++] = x;
}
void change()
{
    int len = strlen(s);
    c = 0; int pos, ok = 0;
    for(int j = 0; j < len; ++j)
    {
        if(s[j] == '@') {
            pos = j;
        }
        if(isupc(s[j])) s[j] += 32;
    }
    if(strcmp(&s[pos + 1], "bmail.com") == 0) ok = 1;
    int j, k;
    for(j = 0; s[j] != '@'; ++j)
    {
        if(ok) {
            if(s[j] == '+') {
                for(k = j; s[k] != '@'; ++k) ;
                j = k;
                break;
            }
            if(s[j] != '.') go(s[j]);
        }
        else go(s[j]);
    }
    for(j = j; j < len; ++j) go(s[j]);
    t[c] = 0;
    str = t;
}
int main()
{
    while(~scanf("%d", &n))
    {
        m.clear();
        int tot = 0;
        for(int i = 1; i <= n; ++i) G[i].clear();
        for(int i = 1; i <= n; ++i)
        {
            scanf("%s", S[i]);
            strcpy(s, S[i]);
            change();
            if(m[str].first)
                m[str].first++;
            else {
                m[str].first++;
                m[str].second = tot++;
            }
            G[ m[str].second ].push_back(i);
        }
        printf("%d\n", tot);
        for(it = m.rbegin(); it != m.rend(); ++it)
        {
            int cnt = (it->second).first;
            printf("%d", cnt);
            int p = (it->second).second;
            for(int i = 0; i < cnt; ++i)
            printf(" %s", S[ G[p][i] ]);
            puts("");
        }
    }
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/orchidzjl/p/4915507.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值