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 ...
随机推荐
- JAVA SE 803 考试前突击
考试的宗旨仍然是掌握基础知识,不过鉴于Oracle的这个认证考试还有不少的大家来找茬的成份在,所以一定一定要细心为上. 关于抽象类的坑点集合: 抽象类不是必须得有抽象方法,但有抽象方法的类必须是抽 ...
- CSS3 页面跳转的动画效果
从左侧弹出: var windowWidth = window.innerWidth; $(atlas_list).css({ "transition":"none&qu ...
- javap生成的字节码
https://www.zhihu.com/question/49470442/answer/135812845http://blog.csdn.net/tzs_1041218129
- Android之GridView控制显示多少行以及遇到的怪事
前段时间接到一个需求,要求GridView超过两行只显示两行多余的不显示.但是GridView没有设置多少行的api,只有设置多少列的方法,到处查找资料都类似的case,stakeoverfrow上面 ...
- Unity3d插件汇总
Unity3d 中的svn插件 插件下载地址:http://www.dehome.net/down/viewfile.php?file_id=53
- Maximum Entropy Markov Models for Information Extraction and Segmentation
1.The use of state-observation transition functions rather than the separate transition and observat ...
- VMware的使用
1.问题的提出 现在所有的组装台式机,均以64位操作系统作为平台 而且USB接口均以USB3.0默认 windows7 64位和windows 10 64位是主流 那么建立在windo ...
- Django:Model的Filter
转自:http://www.douban.com/note/301166150/ django model filter 条件过滤,及多表连接查询.反向查询,某字段的distinct 1.多表 ...
- 【转载】linux tail命令的使用方法详解
本文介绍Linux下tail命令的使用方法.linux tail命令用途是依照要求将指定的文件的最后部分输出到标准设备,通常是终端,通俗讲来,就是把某个档案文件的最后几行显示到终端上,假设该档案有更新 ...
- SNF开发平台WinForm之四-开发-主细表管理页面-SNF快速开发平台3.3-Spring.Net.Framework
4.1运行效果: 4.2开发实现: 4.2.1 有了第一个程序的开发,代码生成器的配置应该是没有问题了,我们只要在对应的数据库中创建我们需要的表结构就可以了,如下: 主表结构如下: ...