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. 【leetcode】Subsets (Medium) ☆

    Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be ...

  2. HDU 1159 Common Subsequence --- DP入门之最长公共子序列

    题目链接 基础的最长公共子序列 #include <bits/stdc++.h> using namespace std; ; char c[maxn],d[maxn]; int dp[m ...

  3. 【XLL API 函数】xlUDF

    调用用户定义函数,这个函数允许DLL 调用 VBA 中的用户定义函数,XLM 宏语言函数,以及在其它 add-ins 中注册的函数. 原型 Excel12(xlUDF, LPXLOPER12 pxRe ...

  4. Hibernate双向一对一对象关系模型映射

    一个员工一辆车:one-to-one 实现一:让汽车表中的外键唯一 create table emp ( eid int primary key auto_increment, ename varch ...

  5. asp.net 上一条和下一条记录的显示

    这里我用的是input标签跳转页面的: 前台aspx页面中: <input class="btn" id="btnSetForm" type=" ...

  6. 基于Spring的可扩展Schema进行开发自定义配置标签支持

    一.背景 最近和朋友一起想开发一个类似alibaba dubbo的功能的工具,其中就用到了基于Spring的可扩展Schema进行开发自定义配置标签支持,通过上网查资料自己写了一个demo.今天在这里 ...

  7. linux中解决SSH连接慢问题 关键点GSSAPIAuthentication

    [root@ok 6FE5-D831]# ssh -v xxx.xxx.xxx.64 OpenSSH_5.3p1, OpenSSL Feb debug1: Reading configuration ...

  8. Python 小游戏 Bunny

    最近在学习Python,所以上网找了一个小程序练练手. 关于这款名为[Bunny]的小游戏,详细请看下面的链接: http://www.oschina.net/translate/beginning- ...

  9. 登录成功,拿到token

    历尽波折,终于成功登录并拿到了token: - (LoginResultDto *)login:(NSString *)userName andPassword:(NSString *)passwor ...

  10. html5 简单音乐播放器

    html5 简单音乐播放器 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> < ...