A - Email Aliases

Time Limit:2000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u

Submit Status

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 (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, addressesACM.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: addressespolycarp+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 Input

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 
2 p+con+test@BMAIL.COM P@bmail.com
1 a@bmail.com.ru
1 a+b@bmail.com.ru
题意:于所有的邮箱,都是由login@domain这样的形式构成,而且字符都是不区分大小写的。 我们有一种特殊类型的邮箱——@bmail.com,这种邮箱除了不区分大小写外—— 1,'@'之前的'.',有等同于无 2,'@'之前的第一个'+'之后的字符可以忽略不计 然后其他字符相同的被认定为邮箱相同。 现在给你n(2e4)个邮箱,让你输出每个邮箱出现的次数与所有这个邮箱的原始串。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MM(a,b) memset(a,b,sizeof(a));
const double eps = 1e-10;
const int inf =0x7f7f7f7f;
const double pi=acos(-1);
const int maxn=20000+100; char s[maxn][105];
char s2[maxn][105];
map<string,int> mp;
vector<int> vec[maxn];
int num=0; void init(int k)
{
for(int i=1;s[k][i]!='\0';i++)
if(s[k][i]>='A'&&s[k][i]<='Z') s2[k][i]=tolower(s[k][i]);
else s2[k][i]=s[k][i]; int p=1;for(;s[k][p]!='@';p++);
if(strcmp(s2[k]+p+1,"bmail.com")==0)
{
int flag=0,cnt=0;
for(int i=1;s[k][i]!='\0';i++)
if((s[k][i]=='.'||flag)&&i<p) continue;
else if(s[k][i]=='+') flag=1;
else s2[k][++cnt]=tolower(s[k][i]);
s2[k][cnt+1]='\0';
}
if(!mp[s2[k]+1])
{num++;
mp[s2[k]+1]=num;
vec[num].push_back(k);}
else {int kk=mp[s2[k]+1];vec[kk].push_back(k);}
} int main()
{
int n;
while(~scanf("%d",&n))
{
MM(s,'\0');MM(s2,'\0');num=0;mp.clear();
for(int i=1;i<=n;i++)
{
scanf("%s",s[i]+1);
init(i);
}
printf("%d\n",num);
for(int i=1;i<=num;i++)
{
printf("%d ",vec[i].size());
for(int j=0;j<vec[i].size();j++)
{
int k=vec[i][j];
printf("%s ",s[k]+1);
}
printf("\n");
}
for(int i=1;i<=num;i++) vec[i].clear();
}
return 0;
}
分析:比赛时确实做出来了,不过用的哈希,而且并没有充分运用好字符串函数,导致写的时间久,
改进:
1.统计字符串个数不一定用哈希,还可以用map<string,int>;
2.比较字符串可以直接调用strcmp()函数;
3,字母小写转大写可以用toupper(),大写转小写可以用tolower();

TTTTTTTTTTTTTTTTTT CodeForces 589A Email Aliases 字符串 map的更多相关文章

  1. codeforces 589A Email Aliases(map)

    Description Polycarp has quite recently learned about email aliases. Of course, he used to suspect t ...

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

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

  3. 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest A Email Aliases(模拟STL vector+map)

    Email AliasesCrawling in process... Crawling failed Time Limit:2000MS     Memory Limit:524288KB     ...

  4. CodeForces - 589A

    题目链接:http://codeforces.com/problemset/problem/589/A Polycarp has quite recently learned about email ...

  5. CodeForces - 589A (STL容器的使用)

    Polycarp has quite recently learned about email aliases. Of course, he used to suspect that the case ...

  6. CodeForces - 589A(字符串处理)

    题目链接:http://codeforces.com/problemset/problem/589/A 题目大意:给定n个邮件地址,任何电子邮件地址都将显示为“login @ domain”,其中: ...

  7. Codeforces 1090B - LaTeX Expert - [字符串模拟][2018-2019 Russia Open High School Programming Contest Problem B]

    题目链接:https://codeforces.com/contest/1090/problem/B Examplesstandard input The most famous characters ...

  8. Codeforces 176B (线性DP+字符串)

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=28214 题目大意:源串有如下变形:每次将串切为两半,位置颠倒形成 ...

  9. java中json包的使用以及字符串,map,list,自定义对象之间的相互转换

    做一个map和字符串的转换,需要导入这些jar包,这是最基本的一些jar包. 经过多方尝试得出结论入下: 首先导入基本包:json-lib-2.2.3-jdk15.jar 如果没有这个jar包,程序是 ...

随机推荐

  1. 牛客 109B 好位置 (字符串水题)

    大意: 给定字符串$s1,s2$, 对于$s1$中所有与$s2$相等的子序列$t$, $t$在$s1$中的下标定义为好位置. 求$s1$是否所有位置都是好位置. 显然$s1$的前缀要与$s2$相等, ...

  2. Spring实战(七)Bean 的作用域

    1.Spring中bean 的多种作用域 单例(Singleton):整个应用中只创建一个bean 的实例,Spring默认创建单例的bean: 原型(Prototype):每次注入or通过Sprin ...

  3. MySQL 事务、视图、索引

    一.事务(Transaction) 1.1 什么是事务? SQL中,事务是指将一系列数据操作捆绑成为一个整体进行统一管理. 如果一个事务执行成功,该事务中进行的所有数据均会提交,称为数据库中的永久组成 ...

  4. 深入理解计算机系统 第十一章 网络编程 part2 第二遍

    客户端和服务器通过因特网这个全球网络来通信.从程序员的观点来看,我们可以把因特网看成是一个全球范围的主机集合,具有以下几个属性: 1.每个因特网主机都有一个唯一的 32 为名字,称为它的 IP 地址 ...

  5. IDirect3DSurface9的D3DFORMAT格式

    /* Formats * Most of these names have the following convention: * A = Alpha * R = Red * G = Green * ...

  6. Java多线程(一):线程与进程

    1.线程和进程 1.1 进程 进程是操作系统的概念,我们运行的一个TIM.exe就是一个进程. 进程(Process)是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位 ...

  7. 移动站Web开发图片自适应两种常见情况解决方案

    本文主要说的是Web中图片根据手机屏幕大小自适应居中显示,图片自适应两种常见情况解决方案.开始吧 在做配合手机客户端的Web wap页面时,发现文章对图片显示的需求有两种特别重要的情况,一是对于图集, ...

  8. EasyUI_前台js_分页

    1.html: <table id="DataTb" title="客户信息" class="easyui-datagrid" sty ...

  9. 【转载】linux SUID SGID

    作者:sparkdev 出处:http://www.cnblogs.com/sparkdev/ setuid 和 setgid 分别是 set uid ID upon execution 和 set ...

  10. linux下共享热点抓包

    Linux有一个抓包工具叫tcpdump,这个命令还是挺强大的.简单列举一下它的参数 # tcpdump -h tcpdump version 4.9.2 libpcap version 1.8.1 ...