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 + ;
typedef pair<int, int> pii;
int n, c;
char S[N][], s[], t[];
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 + ;
else t[c++] = x;
}
void change()
{
int len = strlen(s);
c = ; int pos, ok = ;
for(int j = ; j < len; ++j)
{
if(s[j] == '@') {
pos = j;
}
if(isupc(s[j])) s[j] += ;
}
if(strcmp(&s[pos + ], "bmail.com") == ) ok = ;
int j, k;
for(j = ; 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] = ;
str = t;
}
int main()
{
while(~scanf("%d", &n))
{
m.clear();
int tot = ;
for(int i = ; i <= n; ++i) G[i].clear();
for(int i = ; 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 = ; i < cnt; ++i)
printf(" %s", S[ G[p][i] ]);
puts("");
}
}
return ;
}

codefroces 589A的更多相关文章

  1. Codefroces 1328E Tree Querie(dfs序)

    Codefroces 1328E Tree Querie 题目 给出一棵1为根,n个节点的树,每次询问\(k_i\) 个节点,问是否存在这样一条路径: 从根出发,且每个节点在这条路径上或者距离路径的距 ...

  2. Codefroces 750D:New Year and Fireworks(BFS)

    http://codeforces.com/contest/750/problem/D 题意:烟花会绽放n次,每次会向前推进t[i]格,每次绽放会向左右45°绽放,问有烟花的格子数. 思路:n = 3 ...

  3. Codefroces 750C:New Year and Rating(思维)

    http://codeforces.com/contest/750/problem/C 题意:有n场比赛,每场比赛有一个c,代表比赛结束后分数的增长情况,有一个d,代表这场比赛在div1或者div2打 ...

  4. Codefroces Gym 100781A(树上最长路径)

    http://codeforces.com/gym/100781/attachments 题意:有N个点,M条边,问对两两之间的树添加一条边之后,让整棵大树最远的点对之间的距离最近,问这个最近距离是多 ...

  5. CodeForces 589A Email Aliases (匹配,水题)

    题意:给定于所有的邮箱,都是由login@domain这样的形式构成,而且字符都是不区分大小写的. 我们有一种特殊类型的邮箱——@bmail.com, 这种邮箱除了不区分大小写外—— 1,'@'之前的 ...

  6. codefroces 911G Mass Change Queries

    题意翻译 给出一个数列,有q个操作,每种操作是把区间[l,r]中等于x的数改成y.输出q步操作完的数列. 输入输出格式 输入格式: The first line contains one intege ...

  7. codefroces 297E Mystic Carvings

    problem:一个圆上依次有1~2*n的数字.每个数字都有且只有另一个数字与他相连.选出三条线,使得每条线的两端之间隔的最少点(只包括被选择的6个点)的个数相等.输入输出格式输入格式: The fi ...

  8. Codefroces 850C Arpa and a game with Mojtaba

    Description两个人Van♂游戏.给出$n$个正整数$ai$两人轮流操作,每次选出一个素数$p$和一个幂数$k$,选择的前提为该$n$个数中有$p^{k}$的倍数.接着将所有的$p^{k}$的 ...

  9. codefroces 946G Almost Increasing Array

    Description给你一个长度为$n$的序列$A$.现在准许你删除任意一个数,删除之后需要修改最小的次数使序列单调递增.问最小次数.$1≤n≤200000$ExamplesInput55 4 3 ...

随机推荐

  1. yii 多模板

    main.php: //替换所有模板 //加载文件名为first的模板 //       'theme'=>'theme1', 'components'=>array(           ...

  2. timestamp 类型的索引

    由这条语句datetime.strftime('2014/12/05','%Y/%m/%d')转换出来的索引 是pandas内置类型相同,如果使用datetime.strftime('2014/12/ ...

  3. Java大数处理类:BigInteger类和BigDecimal类

    当我们要处理非常大的数据时,平常用的数据类型已不足以表示,在Java中有两个类BigInteger和BigDecimal分别表示大整数类和大浮点数类,这两个类在理论上只要计算机内存足够大就能够表示无线 ...

  4. React之JSX入门

    React是由ReactJS与React Native组成,其中ReactJS是Facebook开源的一个前端框架,React Native 是ReactJS思想在native上的体现! JSX并不是 ...

  5. struts2中一些常用的写法 记录

    1.对日期进行处理 Date current = new Date(); java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat ...

  6. Dubbo应用与异常记录

    结合项目里使用暴露出的问题,对并发较多的核心业务或者对请求失败等敏感的业务场景不太建议使用Dubbo, 如电商的购买等行为,使用Dubbo就必须阅读源码,熟悉相关机制,或者直接自己造轮子. >& ...

  7. Oracle如何写出高效的SQL

    转载:http://www.blogjava.net/ashutc/archive/2009/07/19/277215.html 1.选择最有效率的表明顺序(只在基于规则的优化器中有效) Oracle ...

  8. 【叉积】【sdut 2508 图形密码】

    图形密码 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 题目链接:http://acm.sdut.edu.cn/sdutoj/p ...

  9. OCJP(1Z0-851) 模拟题分析(三)over

    Exam : 1Z0-851 Java Standard Edition 6 Programmer Certified Professional Exam 以下分析全都是我自己分析或者参考网上的,定有 ...

  10. 搜索引擎爬虫技术研究(爬虫框架)-WebCollector

    一.简介: https://github.com/CrawlScript/WebCollector/blob/master/README.zh-cn.md 二.使用: <dependency&g ...