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 (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
6
ICPC.@bmail.com
p+con+test@BMAIL.COM
P@bmail.com
a@bmail.com.ru
I.cpc@Bmail.Com
a+b@bmail.com.ru
4
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 代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
using namespace std;
typedef long long LL;
const int MAXN = 2e4+;
const double eps = 1e-;
char str[MAXN];
char S[MAXN];
map <string, int> mp;
vector<string> vec[MAXN];
int main()
{
int n;
while(cin>>n)
{
for(int i=; i<MAXN; i++)
vec[i].clear();
mp.clear();
int tmp = , ans = ;
for(int i=; i<n; i++)
{
cin>>str;
strcpy(S,str);
int len = strlen(str);
for(int ii=; ii<len; ii++)
{
if(str[ii]>='A'&&str[ii]<='Z')
str[ii] = str[ii]+'a'-'A';
if(str[ii] == '@')
tmp = ii;
}
if(strcmp(str+tmp+,"bmail.com")==)
{
int l = ;///变化之后的长度
for(int j=; j<tmp; j++)
{
if(str[j] == '.')
continue;
if(str[j] == '+')
break;
str[l++] = str[j];
}
for(int j=tmp; str[j]; j++)
str[l++] = str[j];
str[l] = '\0';
}
if(mp.find(str) == mp.end())///判断有没有相同
mp[str] = ans++;
int tt = mp[str];
vec[tt].push_back(S);
}
cout<<ans<<endl;
for(int i=; i<ans; i++)
{
cout<<vec[i].size();
for(int j=; j<vec[i].size(); j++)
cout<<" "<<vec[i][j];
puts("");
}
}
return ;
}
map与vector---Email Aliases的更多相关文章
- 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 ...
- codeforces 589A Email Aliases(map)
Description Polycarp has quite recently learned about email aliases. Of course, he used to suspect t ...
- TTTTTTTTTTTTTTTTTT CodeForces 589A Email Aliases 字符串 map
A - Email Aliases Time Limit:2000MS Memory Limit:524288KB 64bit IO Format:%I64d & %I64u ...
- PAT甲题题解-1022. Digital Library (30)-map映射+vector
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789235.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- [uva11991]map和vector的入门
给你一个长度为n的数组,进行m次询问,每次询问输入k和v,输出第k次出现v时的下标是多少. n<=1e6 用vector动态开空间,map使数值结合.map每次查找效率大约为logn. map的 ...
- UVA12096 集合栈计算机(map和vector实现双射关系+集合的交并运算的STL)
题目大意: 对于一个以集合为元素的栈,初始时栈为空. 输入的命令有如下几种: PUSH:将空集{}压栈 DUP:将栈顶元素复制一份压入栈中 UNION:先进行两次弹栈,将获得的集合A和B取并集,将结果 ...
- PAT 1039 Course List for Student (25分) 使用map<string, vector<int>>
题目 Zhejiang University has 40000 students and provides 2500 courses. Now given the student name list ...
- Educational Codeforces Round 108 (Div. 2), C map套vector存储
地址 Problem - C - Codeforces 题目 题意 一个学校有n个人参加比赛,他们分别属于ui队,每个人的能力值为si 当每个队需要1~n个人的时候,这个学校能参加的人的能力值和最大 ...
- c++ map、vector、list
总体来说,使用map最简单.支持查找,获取下标不存在也不会出错 map是使用rbtree结构, vector是用连续获取内存的方法,类似hash结构.list是链表结构, 不支持下标. map: 支持 ...
- map 和 vector 的erase函数说明
1. map的erase函数使用 这里首先要注意,C++针对map的erase函数有不同的函数原型,这往往是出现问题的关键所在.根据参考文献1: 在C++98中: (1) void erase (it ...
随机推荐
- 使用Struts+Hibernate开发学生信息管理系统
1.项目组织结构 2.web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app vers ...
- alt属性和title属性差异---终于分清楚了!
凡是接触过前端的开发者,相信都会接触到<img>标签,自然alt title更是不会陌生,但对他们真正的含义和使用方法,你确定了解吗? 参考: http://www.junchenwu.c ...
- 公钥、私钥、CA认证、数字签名、U盾
感谢传智播客的方立勋老师,在一个教学视频上,他巧妙地以蒋介石给宋美龄写密信作为例子,生动地讲述了软件密码学知识. 加密分为对称加密和非对称加密,我们传统理解的,发送数据之前使用一个加密器加密,接到数据 ...
- 使用SQL联合查询来构建临时vo对象的应用
联合查询: 表1: team球队表 表2:schedule 赛程表 需要数据: 球队名称.主队ID.主队名称.客队ID.客队名称.胜负情况 方法1. Object数组取出列和数值 import jav ...
- Log4j配置说明及样例
一般的应用都会记录日志,Java圈里面用得最多就属log4j了,比较规范一点就是使用log4j.xml进行配置Log输出.这里就比较有疑问,多数情况是使用log4j.properties文件呐,前面也 ...
- ubuntu 安装bochs
//首先官网下载bochs源码wget http://bochs.sourceforge.net/svn-snapshot/bochs-20150503.tar.gz//然后解压 tar vxzf b ...
- 进阶学习js中的执行上下文
在js中的执行上下文,菜鸟入门基础 这篇文章中我们简单的讲解了js中的上下文,今天我们就更进一步的讲解js中的执行上下文. 1.当遇到变量名和函数名相同的问题. var a = 10; functio ...
- windows下远程连接ubantu
要实现windows下连接ubantu需要安装以下软件: 1. windows下安装winSCP 2. Ubantu下安装OpenSSH Server 可以使用命令行安装openSSH Server: ...
- shell的重定向
>file 将file文件重定向为输出源,新建模式,可以将正确的结果输出到file文件 >>file 将file文件重定向为输出源,追加模式 <file 将file文件重定 ...
- Linux的段错误调试方法
linux段错误的调试方法 相关博文: http://blog.csdn.net/htianlong/article/details/7439030 http://www.cnblogs.com/pa ...