codeforces 589A Email Aliases(map)
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.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.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 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
题意:有两种邮件第一种:@bmail 第二种L:@bmain.xxx。对于第一种邮件格式我们要求在@前的 . 忽略,对于@前第一个出现的+后面的内容直到@全部删除,给你n个邮件地址,让你把它们分组,并把每组所包含的
邮件数 和 邮件都打印出来。
分析: map搞。
/*************************************************************************
> File Name: 365A.cpp
> Author:
> Mail:
> Created Time: 2016年07月29日 星期五 20时54分32秒
************************************************************************/ #include<iostream>
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e4 + ;
map<string,int> mp;
map<string,int> :: iterator it;
int num[maxn];
vector<string> a[maxn];
char cnt[] ={"bmail.com"};
char str[],str1[]; int main()
{
int n;
cin >> n;
int id = ;
mp.clear();
while(n--)
{
cin >> str;
strcpy(str1,str);
int st;
for(int i = ; str1[i]; i++)
{
str1[i] = tolower(str1[i]);
if(str1[i] == '@') st = i;
}
if(strcmp(str1 + st + ,cnt) == )
{
int t = ;
for(int i = ; i< st; i++)
{
if(str1[i] == '.') continue;
if(str1[i] == '+') break;
str1[t++] = str1[i];
}
for(int i = st; str1[i];i++)
{
str1[t++] = str1[i];
}
str1[t] = ;
}
if(mp.find(str1) == mp.end()) mp[str1] = ++id;
int ss = mp[str1];
++num[ss];
a[ss].push_back(str);
}
cout << id << endl;
for(int i = ; i<= id; i++)
{
cout << num[i] << endl;
for(int j = ; j< a[i].size(); j++) cout << ' ' << a[i][j];
cout << endl;
}
return ;
}
codeforces 589A Email Aliases(map)的更多相关文章
- TTTTTTTTTTTTTTTTTT CodeForces 589A Email Aliases 字符串 map
A - Email Aliases Time Limit:2000MS Memory Limit:524288KB 64bit IO Format:%I64d & %I64u ...
- CodeForces 589A Email Aliases (匹配,水题)
题意:给定于所有的邮箱,都是由login@domain这样的形式构成,而且字符都是不区分大小写的. 我们有一种特殊类型的邮箱——@bmail.com, 这种邮箱除了不区分大小写外—— 1,'@'之前的 ...
- 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
题目链接:http://codeforces.com/problemset/problem/589/A Polycarp has quite recently learned about email ...
- CodeForces - 589A (STL容器的使用)
Polycarp has quite recently learned about email aliases. Of course, he used to suspect that the case ...
- CROC 2016 - Qualification C. Hostname Aliases map
C. Hostname Aliases 题目连接: http://www.codeforces.com/contest/644/problem/C Description There are some ...
- Codeforces 977F - Consecutive Subsequence - [map优化DP]
题目链接:http://codeforces.com/problemset/problem/977/F 题意: 给定一个长度为 $n$ 的整数序列 $a[1 \sim n]$,要求你找到一个它最长的一 ...
- CodeForces 567C. Geometric Progression(map 数学啊)
题目链接:http://codeforces.com/problemset/problem/567/C C. Geometric Progression time limit per test 1 s ...
- Codeforces 567C - Geometric Progression - [map维护]
题目链接:https://codeforces.com/problemset/problem/567/C 题意: 给出长度为 $n$ 的序列 $a[1:n]$,给出公比 $k$,要求你个给出该序列中, ...
随机推荐
- Linux Kernel 5.1 RC5发布
我们距离正式的Linux 5.1内核发布还有不到一个月的时间,而今天Linus Torvalds宣布推出预期的Linux Kernel 5.1 RC5版本.Linus Torvalds专门评论了Lin ...
- sed 替换 引用变量值,记录一个自己学习错误的地方。
先上脚本,脚本的目的是虚拟机克隆-连接克隆,然后修改ip这个搞定,修改hostname就很简单了 declare oldipdeclare -i Anamedeclare newipoldip=`ca ...
- JAVA Web项目获取src和WebContent目录下的配置文件
一,获取src下面的配置文件信息 1,结构图如下: package com.binp.properties; import java.io.FileInputStream; import java.i ...
- jeesite 简介
jeesite 简介 https://github.com/thinkgem/jeesite http://jeesite.com/
- Android Bitmap太大导致ImageView不显示的问题
今天做我们的智能相冊的项目时,遇到了非常奇妙的问题,当照片太大时,导致ImageView.setImageBitmap不显示,上网上搜了非常多办法.感觉都不是那么靠谱.最后使用了简单粗暴的手段: // ...
- 关于Android制作.9.png图片
第一个问题,.9格式的图片与我们之前的一般图片有什么问题呢? 这是安卓开发里面的一种特殊的图片. 这样的格式的图片在android 环境下具有自适应调节大小的能力. (1)同意开发者定义可扩展区域,当 ...
- JavaScript中的Array对象方法调用
方法concat for 循环与for in 循环 <html> <head> <script type="text/javascript"> ...
- CodeForces 550B Preparing Olympiad(DFS回溯+暴力枚举)
[题目链接]:click here~~ [题目大意] 一组题目的数目(n<=15),每一个题目有对应的难度,问你选择一定的题目(大于r个且小于l个)且选择后的题目里最小难度与最大难度差不小于x, ...
- Android体验高扩展艺术般的适配器
前言 本篇文章带大家体验一下一种具有扩展性的适配器写法. 这个适配器主要用于Item有多种的情况下.当然仅仅有一种类型也是适用的 实现 毫无疑问我们要继承BaseAdapter,重写getCount, ...
- lua实现大数运算
lua实现的大数运算,代码超短,眼下仅仅实现的加减乘运算 ------------------------------------------------ --name: bigInt --creat ...