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.com addresses, 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.comand 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.comand 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.comaddresses.

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.

Examples

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
Output
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
题意:给出你n个邮箱地址(由 登录名+@+域名组成),对于所有邮箱地址,他们忽视大小写的不同(AcB@qq.com和acb@Qq.CoM是同一个邮箱地址,acbc@qq.com和acb@qq.com不是同一个邮箱地址,因为他们登陆名不一样),
对于特殊域名bmail.com,它忽视登陆名中 所有的“.”和第一个“+”到“@”这部分的所有字符
(ICPC.@bmail.com和I.cpc@Bmail.Com 是同一个邮箱地址,p+con+test@BMAIL.COM和P@bmail.com也是同一个邮箱地址;a@bmail.com.ru和a+b@bmail.com.ru不是同一个邮箱地址,因为bmail.com.ru不是特殊域名,它不能忽略“+”到“@”这段的所有字符)
要你输出有多少个不同的邮箱地址,并把所有的相同邮箱地址输出在一起。
域名除字母大小写外要完全一样,字符数不能多也不能少,否则就是不同域名。例:“bmail.com.ru”和“bmail.com”就是不同域名
思路:把所有输入的邮箱地址字符串化为标准串,然后把标准串一样的字符串放在一起。
我是用map容器保存标准串,创建一个map<string,int>类型的容器,第一个位置存标准串,第二个位置存放该标准串对应的vector数组的序号,vector数组保存相同标准串的原字符串的下标,最后遍历所有vector数组输出答案。
map的使用方法:https://www.cnblogs.com/cglongge/p/8982556.html
vector的使用方法:http://www.cnblogs.com/cglongge/p/8569934.html
string的使用方法:http://www.cnblogs.com/cglongge/p/8987427.html
代码:
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
using namespace std;
struct st{//存放原字符串
string str;
}s[20010];
map<string,int> mp;//存放对于标准串的数组序号
struct{//存放相同标准串的原字符串的下标
vector<int> v;
}ans[20010];
string check(string a){
string b="moc.liamb@",c;//特殊域名
int i,j,k;
bool lg=false;
k=-1;
for(i=a.size()-1;i>=0&&k==-1;i--){//截取域名
if(a[i]=='@'){
c.push_back(a[i]);
k=i;
}
else{
if(a[i]>='A'&&a[i]<='Z')//化为标准串
a[i]+=32;
c.push_back(a[i]);
}
}
//cout<<" 1 "<<b<<endl;
//cout<<" 2 "<<c<<endl;
if(b==c){//是特殊域名
b.clear();
for(i=0;i<k;i++){
if(a[i]=='+')//去掉‘+’到‘@’这段字符串和‘. ’
break;
else if(a[i]>='A'&&a[i]<='Z'){
a[i]+=32;
b.push_back(a[i]);
}
else if(a[i]>='a'&&a[i]<='z'){
b.push_back(a[i]);
}
}
}
else{
b.clear();
for(i=0;i<k;i++){
if(a[i]>='A'&&a[i]<='Z'){
a[i]+=32;
b.push_back(a[i]);
}
else
b.push_back(a[i]);
}
}
reverse(c.begin(),c.end());
b=b+c;//得到标准串
return b;
}
int main(){
int n;
int i,j;
cin>>n;
string a;
int cnt;
cnt=0;
for(i=0;i<n;i++){
cin>>s[i].str;
a=check(s[i].str);
//cout<<a<<endl;
map<string,int>::iterator it;
it=mp.find(a);
if(it!=mp.end()){//如果有一样的标准串
ans[mp[a]].v.push_back(i);//放入对应序号的答案数组内
}
else{
mp.insert(pair<string,int>(a,cnt));//建立一个新的标准串和答案数组的连接
//cout<<a<<" "<<cnt<<endl;
ans[cnt].v.push_back(i);//
cnt++;
}
}
cout<<cnt<<endl;
for(i=0;i<cnt;i++){//输出一样的邮箱地址
int len=ans[i].v.size();
cout<<len;
for(j=0;j<len;j++){
cout<<" "<<s[ans[i].v[j]].str;
}
cout<<endl;
}
return 0;
}

  





CodeForces - 589A (STL容器的使用)的更多相关文章

  1. STL容器set用法以及codeforces 685B

    以前没怎么用过set,然后挂训练赛的时候发现set的妙用,结合网上用法一边学一边写. 首先set是一种容器,可以跟其他STL容器一样用 set<int > s 来定义, 它包含在STL头文 ...

  2. STL容器

    啦啦啦,今天听啦高年级学长讲的STL容器啦,发现有好多东西还是有必要记载的,毕竟学长是身经百战的,他在参加各种比赛的时候积累的经验可不是一天两天就能学来的,那个可是炒鸡有价值的啊,啊啊啊啊啊 #inc ...

  3. c++ stl容器set成员函数介绍及set集合插入,遍历等用法举例

    c++ stl集合set介绍 c++ stl集合(Set)是一种包含已排序对象的关联容器.set/multiset会根据待定的排序准则,自动将元素排序.两者不同在于前者不允许元素重复,而后者允许. 1 ...

  4. STL容器删除元素的陷阱

    今天看Scott Meyers大师的stl的用法,看到了我前段时间犯的一个错误,发现我写的代码和他提到错误代码几乎一模一样,有关stl容器删除元素的问题,错误的代码如下:std::vector< ...

  5. 【转】c++中Vector等STL容器的自定义排序

    如果要自己定义STL容器的元素类最好满足STL容器对元素的要求    必须要求:     1.Copy构造函数     2.赋值=操作符     3.能够销毁对象的析构函数    另外:     1. ...

  6. GDB打印STL容器内容

    GDB调试不能打印stl容器内容,下载此文件,将之保存为~/.gdbinit就可以使用打印命令了. 打印list用plist命令,打印vector用pvector,依此类推. (gdb) pvecto ...

  7. STL容器迭代器失效分析

    连续内存序列容器(vector, string, deque) 对于连续内存序列STL容器,例如vector,string,deque,删除当前iterator会使得后面所有的iterator都失效, ...

  8. STL容器的适用情况

     转自http://hsw625728.blog.163.com/blog/static/3957072820091116114655254/ ly; mso-default-props:yes; m ...

  9. STL容器的遍历删除

    STL容器的遍历删除 今天在对截包程序的HashTable中加入计时机制时,碰到这个问题.对hash_map中的每个项加入时间后,用查询函数遍历hash_map,以删除掉那些在表存留时间比某个阈值长的 ...

  10. STL容器与配接器

    STL容器包括顺序容器.关联容器.无序关联容器 STL配接器包括容器配接器.函数配接器 顺序容器: vector                             行为类似于数组,但可以根据要求 ...

随机推荐

  1. Python 进程之间共享数据

    最近遇到多进程共享数据的问题,到网上查了有几篇博客写的蛮好的,记录下来方便以后查看. 一.Python multiprocessing 跨进程对象共享  在mp库当中,跨进程对象共享有三种方式,第一种 ...

  2. IP通信基础学习第二周

    此周的课程学习应该算是我对此科目真正学校生涯的开始吧,尽管我对该科目仍感到很陌生. 课程一开头,老师就给我们简单的介绍了网络的定义.发展及其分类,重点讲了网络拓扑结构及其在局域网上具体的分层情况.该部 ...

  3. mysql查询语句and,or

    where查询里,常用到and,or and SELECT field1, field2,...fieldN FROM table_name1, table_name2... WHERE condit ...

  4. 01:云计算三种服务模式SaaS、PaaS和IaaS

    1.1 云计算 1.什么是云计算 1. 云计算服务是指将大量用网络连接的计算资源统一管理和调度,构成一个计算资源池向用户按需服务. 2. 用户通过网络以按需.易扩展的方式获得所需资源和服务(资源包括网 ...

  5. 对比Python中_,__,xx__xx

      对比Python中_,__,xx__xx _ 的含义 不应该在类的外面访问,也不会被from M import * 导入. Python中不存在真正的私有方法.为了实现类似于c++中私有方法,可以 ...

  6. 【Alpha】Scrum Meeting 2

    前言 第2次会议在3月28日由PM在教一317召开. 主要确定了项目方向和目标功能,进行了任务分工.时长60min. 任务分配 姓名 当前阶段任务 下阶段任务 吴昊 熟悉代码和配置环境,发布手机端博客 ...

  7. 从GitHub远程仓库中删除文件夹或文件

    在上传项目到github时,忘记忽略了某个文件夹target,就直接push上去了, 最后意识到了此问题,决定删除掉远程仓库中的target文件夹 删除前: 删除后: 在github上只能删除仓库,却 ...

  8. asp.net json,对象,字符串的相互转换

    //object 转json格式字符串 public static string ObjectToJsonString(this object obj) { return JsonConvert.Se ...

  9. AJAX缓存清理

    Ajax页面缓存是ajax处理数据时对一些重复相同数据进行一个缓存操作,这样从另一个层面对于我们来讲是非常的不错了,但有时我们并不希望它缓存要如何处理呢?下面我们一起来看看关于页面缓存问题分析与解决, ...

  10. Linux 常用命令——文件处理命令

    Linux 常用命令 Linux Linux命令格式 命令格式:命令 [-选项] [参数] 例如:ls -a /etc 说明: 1.当有多个选项时,可以写在一起 2.简化选项等于完整选项 -a = - ...