CodeForce 589A Email Aliases

Email Aliases

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 "[email protected]", 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.com addresses, 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 [email protected] and [email protected] correspond to the same account. Similarly, addresses [email protected] and [email protected] 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 [email protected], [email protected] and [email protected] also correspond to the same account on the server bmail.com. However, addresses [email protected] and [email protected] 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.

Examples

Input

6[email protected][email protected][email protected][email protected][email protected][email protected]

Output

42 [email protected] [email protected] 2 [email protected] [email protected] 1 [email protected] 1 [email protected] 

题意:  给你一些邮箱,忽略大小写(这是个大前提),有一种特殊邮箱 @bmail.com 这种邮箱有二个特殊地方:  (1)忽略前面的‘.’这个符号,(2)无视第一个‘+’到‘@’的字符思路:  同学用了两重for循环结果,无情超时;  最好是输入一个处理一个,和前面一样的放进去。AC代码

 1 # include <iostream>
 2 # include <cstring>
 3 # include <cstdio>
 4 # include <vector>
 5 # include <map>
 6 using namespace std;
 7
 8 const int MAX = 2* 1e4 + 1;
 9
10 char s[MAX][105];
11 char s2[MAX][105];
12 map <string, int> mp;
13 vector <int> v[MAX];
14 int num = 0;
15
16 void init(int k)
17 {
18     // 转换大小写
19     for(int i = 1; s[k][i] != ‘\0‘; i++)
20         if(s[k][i] >= ‘A‘ && s[k][i] <= ‘Z‘)
21             s2[k][i] = tolower(s[k][i]);
22         else
23             s2[k][i]=s[k][i];
24
25     int p = 1;
26     for(; s[k][p] != ‘@‘; p++); // 找@
27
28     //  判段字符串相同吗
29     if(strcmp(s2[k] + p + 1, "bmail.com") == 0)
30     {
31         int flag = 0, cnt = 0;
32         for(int i = 1; s[k][i] != ‘\0‘; i++)
33         {
34             if((s[k][i] == ‘.‘ || flag) && i < p)
35                 continue;
36             else if(s[k][i] == ‘+‘)
37                 flag = 1;
38             else
39                 s2[k][++cnt] = tolower(s[k][i]);
40         }
41             s2[k][cnt+1] = ‘\0‘;
42     }
43     if(!mp[s2[k] + 1])
44     {
45         num++;
46         mp[s2[k] + 1] = num;
47         v[num].push_back(k);
48     }
49     else
50         v[mp[s2[k]+1]].push_back(k);
51 }
52
53 int main()
54 {
55     int n;
56     scanf("%d", &n);
57
58
59     for(int i = 1; i <= n; i++)
60     {
61         scanf("%s", s[i] + 1);
62         init(i);
63     }
64     printf("%d\n", num);
65
66     for(int i = 1; i <= num; i++)
67     {
68         printf("%d ", v[i].size());
69         for(int j = 0; j < v[i].size(); j++)
70             printf("%s ",s[v[i][j]] + 1);
71
72         printf("\n");
73     }
74     for(int i = 1; i <= num; i++)
75         v[i].clear();
76
77    return 0;
78 }

				
时间: 2024-12-29 07:24:09

CodeForce 589A Email Aliases的相关文章

codeforces 589A Email Aliases(map)

Description 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 (character

CodeForces 589 Email Aliases (匹配,水题)

题意:给定于所有的邮箱,都是由[email protected]这样的形式构成,而且字符都是不区分大小写的. 我们有一种特殊类型的邮箱——@bmail.com, 这种邮箱除了不区分大小写外—— 1,'@'之前的'.',有等同于无 2,'@'之前的第一个'+'之后的字符可以忽略不计 然后其他字符相同的被认定为邮箱相同. 现在给你 n 个邮箱,让你输出每个邮箱出现的次数与所有这个邮箱的原始串. 析:没什么好说的,就是先判断不是@bmail.com,然后再按要求去点,去+和@之间的值,然后一个一个的比

map与vector---Email Aliases

Description 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 (character

rancid install file

What is Rancid ? RANCID monitors a router's (or more generally a device's) configuration,including software and hardware (cards, serial numbers, etc) and uses CVS (Concurrent Version System) or Subversion to maintain history of changes. What RANCID D

[转]建立大容量基于Web的Email系统

建立大容量基于Web的Email系统 王波 最近几年来,基于Web的免费Email系统非常流行.当前,几个著名的免费Email网站基本上已经成为大多数人的选择,建立单纯提供免费Email服务的站点不再像以前那样受到热烈欢迎,但是提供Web界面的Email服务已经成为了一个商业站点为其注册成员提供的基本服务之一. 一个Email系统可以分为服务器端和客户端,Web界面的Email系统则是将Email客户放在了Web服务器端,因此Email系统所需要实现的是一个Web界面的Email客户.然而,由于

Zabbix用Email介质SMTP发送报警

Zabbix报警大部分使用的是脚本报警,这次我们用SMTP方式发送报警. 在zabbix上设置好了EMail账号还不行,还要在系统里装发送邮件的服务,我们这里用SendMail. 环境: CentOS Linux release 7.1.1503 (Core) 1.检查系统是否安装SendMail. #rpm -qa | grep Sendmail 返回值为空,说明没有安装过. 2.用yum list sedmail看看都需要安装哪些包 #yum list sedmail 3.安装Sendmai

email

################email#######基本电子邮件发送 电子邮件发送1 .服务器使用SMTP协议将电子邮件提交至TCP端口25,或由本地客户端通过/usr/bin/sendmail程序进行提交.如果该MTA是最终目标位置,邮件将传递至MDA.否则,将使用MX记录在DNS中查找下一个MTA,并使用SMTP进行转发.2 .MDA:"邮件发送代理".MDA将邮件发送至收件人的本地邮件存储位置(默认情况下是/var/spool/mail/user).Postfix提供自己的M

CentOS7部署DNS和E-mail服务

配置DNS服务 安装bind包 yum install bind bind-utils 编辑主配置文件,更改如下参数 vi /etc/named.conf listen-on port 53 { any; }; allow-query     { any; }; include "/etc/named.rfc1912.zones"; 定义zone,正向和反向解析配置 vi /etc/named.rfc1912.zones zone "localyum.com" IN

B - Email from Polycarp

Methodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly one sy