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 + ;
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的更多相关文章
- Codefroces 1328E Tree Querie(dfs序)
Codefroces 1328E Tree Querie 题目 给出一棵1为根,n个节点的树,每次询问\(k_i\) 个节点,问是否存在这样一条路径: 从根出发,且每个节点在这条路径上或者距离路径的距 ...
- Codefroces 750D:New Year and Fireworks(BFS)
http://codeforces.com/contest/750/problem/D 题意:烟花会绽放n次,每次会向前推进t[i]格,每次绽放会向左右45°绽放,问有烟花的格子数. 思路:n = 3 ...
- Codefroces 750C:New Year and Rating(思维)
http://codeforces.com/contest/750/problem/C 题意:有n场比赛,每场比赛有一个c,代表比赛结束后分数的增长情况,有一个d,代表这场比赛在div1或者div2打 ...
- Codefroces Gym 100781A(树上最长路径)
http://codeforces.com/gym/100781/attachments 题意:有N个点,M条边,问对两两之间的树添加一条边之后,让整棵大树最远的点对之间的距离最近,问这个最近距离是多 ...
- CodeForces 589A Email Aliases (匹配,水题)
题意:给定于所有的邮箱,都是由login@domain这样的形式构成,而且字符都是不区分大小写的. 我们有一种特殊类型的邮箱——@bmail.com, 这种邮箱除了不区分大小写外—— 1,'@'之前的 ...
- codefroces 911G Mass Change Queries
题意翻译 给出一个数列,有q个操作,每种操作是把区间[l,r]中等于x的数改成y.输出q步操作完的数列. 输入输出格式 输入格式: The first line contains one intege ...
- codefroces 297E Mystic Carvings
problem:一个圆上依次有1~2*n的数字.每个数字都有且只有另一个数字与他相连.选出三条线,使得每条线的两端之间隔的最少点(只包括被选择的6个点)的个数相等.输入输出格式输入格式: The fi ...
- Codefroces 850C Arpa and a game with Mojtaba
Description两个人Van♂游戏.给出$n$个正整数$ai$两人轮流操作,每次选出一个素数$p$和一个幂数$k$,选择的前提为该$n$个数中有$p^{k}$的倍数.接着将所有的$p^{k}$的 ...
- codefroces 946G Almost Increasing Array
Description给你一个长度为$n$的序列$A$.现在准许你删除任意一个数,删除之后需要修改最小的次数使序列单调递增.问最小次数.$1≤n≤200000$ExamplesInput55 4 3 ...
随机推荐
- zmq-ios framwork
1.附件见zeromq-ios.framework百度网盘/iOS/zmq 2.zeromq-ios.framework解压拖进工程文件 3.objc-zmq见百度网盘/iOS/zmq 4.objc- ...
- 利用CocoaPods,在项目中导入AFNetworking类库
场景1:利用CocoaPods,在项目中导入AFNetworking类库 AFNetworking类库在GitHub地址是:https://github.com/AFNetworking/AFNetw ...
- 命名空间 - PHP笔记
转: 概述 命名空间是一种封装事物的方法.在很多地方都可以见到这种抽象概念,比如在操作系统中,目录用来将相关文件分组,对于目录中的文件来说,目录就扮演了命名空间的角色.这个原理应用到程序设计领域就是命 ...
- LeetCode : 93. Restore IP Addresses
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABZ4AAAHUCAYAAAC6Zj2HAAAMFGlDQ1BJQ0MgUHJvZmlsZQAASImVlw
- 使用dynatrace+showslow进行前端性能测试
1.背景 应用的性能测试与优化目前主要停留在服务器端的反馈,而对于前端性能标准的研究与测试相对比较空白,缺乏统一的标准与工具.众所周知,浏览器html组件的下载及渲染性能直接影响最终的用户体验,目前应 ...
- Asp.Net - 8.多线程
8.1 概念 进程(Process):是Windows系统中的一个基本概念,它包含着一个运行程序所需要的资源.进程之间是相对独立的,一个进程无法直接访问另一个进程的数据(除非利用分布式计算方式),一个 ...
- 与你相遇好幸运,Waterline的属性
>支持的数据类型: string / text / integer / float / date / time / datetime / boolean / binary / array / j ...
- JavaScript Canvas 根据像素点取位置
<html> <body> <canvas id="canvas" width="100" height="100&qu ...
- 【PHP&&mysqli】
msyqli和mysql只有一个字母的差别,真正的含义是msyql的增强版扩展. MySQL可以处理满足程序员对MySQL数据库操作的各种需要了,为什么还需要mysqli呢?因为mysqli支持面性对 ...
- 如何观察JS的事件队列的执行划分
也就是说,不同的操作函数,操作符,JS将其放入事件队列是不一样的... 比如: 外部函数和内部函数,就是分两次放入事件循环的尾端的. 比如,多个操作符组成的链式操作,也有可能是放不同的操作批次进入事件 ...