CodeForces - 589A
题目链接:http://codeforces.com/problemset/problem/589/A
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.
Examples
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
题目大意:输入n,代表有n个字符串,每个字符串分为两部分s1@s2。不需要考虑字母大小写,如果s2是bmail.com结尾的,不需要考虑 . 和第一个+号到@之间的字符。 问你属于同一类的字符串有多少个,按照
输入顺序输出
思路:用map来存字符串和它是第几个,当然这里的字符串是指消去了可以消去的字符之后的字符串,用vector来存储答案
具体看代码
#include<iostream>
#include<string.h>
#include<map>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<set>
#include<queue>
typedef long long ll;
using namespace std;
const ll mod=1e9+;
const int maxn=2e4+;
const int maxk=+;
const int maxx=1e4+;
const ll maxe=+;
#define INF 0x3f3f3f3f3f3f
#define Lson l,mid,rt<<1
#define Rson mid+1,r,rt<<1|1
map<string,int>mp;//用于存储属于同一类的字符串的下标
vector<string>v[maxn];//存储不同类别的字符串
char a[maxn][],b[maxn][],code[];
int main()
{
int n,id=;
cin>>n;
for(int i=;i<n;i++)
{
cin>>a[i];
strcpy(b[i],a[i]);
int j=;
while(a[i][j]!='\0')
{
a[i][j]=tolower(a[i][j]);//将所有大写转换成小写字母
j++;
}
}
for(int i=;i<n;i++)
{
int j=,cnt=,flag=;
while(a[i][j]!='@') {cnt++;j++;}
strcpy(code,a[i]);
if(strcmp(a[i]+cnt+,"bmail.com")==)
{
for(j=;j<cnt;j++)
{
if(a[i][j]=='+') {flag=j;break;}
} int sum=;
for(j=;j<(flag==?cnt:flag);j++)
{
if(a[i][j]=='.') continue;
code[sum++]=a[i][j];
}
code[sum]='\0';//注意要加\0,结束标志
}
if(!mp.count(code))
{
mp[code]=id;//如果该类还没有出现过,则存储下来
v[id].push_back(b[i]);//同时放进v中
id++;
}
else
{
v[mp[code]].push_back(b[i]);//该类已经存在了,直接放入
}
}
printf("%d\n",id);
for(int j=;j<id;j++)
{
int len=v[j].size();
printf("%d",len);
for(int k=;k<len;k++)
printf(" %s",v[j][k].c_str());
printf("\n");
}
return ;
}
CodeForces - 589A的更多相关文章
- CodeForces - 589A(二分+贪心)
题目链接:http://codeforces.com/problemset/problem/589/F 题目大意:一位美食家进入宴会厅,厨师为客人提供了n道菜.美食家知道时间表:每个菜肴都将供应. 对 ...
- CodeForces - 589A(字符串处理)
题目链接:http://codeforces.com/problemset/problem/589/A 题目大意:给定n个邮件地址,任何电子邮件地址都将显示为“login @ domain”,其中: ...
- CodeForces 589A Email Aliases (匹配,水题)
题意:给定于所有的邮箱,都是由login@domain这样的形式构成,而且字符都是不区分大小写的. 我们有一种特殊类型的邮箱——@bmail.com, 这种邮箱除了不区分大小写外—— 1,'@'之前的 ...
- CodeForces - 589A (STL容器的使用)
Polycarp has quite recently learned about email aliases. Of course, he used to suspect that the case ...
- 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 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
随机推荐
- Select\Poll\Epoll异步IO与事件驱动
事件驱动与异步IO 事件驱动编程是一种编程规范,这里程序的执行流由外部事件来规定.它的特点是包含一个事件循环,但外部事件发生时使用回调机制来触发响应的处理.另外两种常见的编程规范是(单线程)同步以及多 ...
- java代码Math.sqrt
总结:这个判断小数的题目,当时全只2有一个人想出了结果.老师很开心.我很桑心~~~~ 我没想到要取膜,我只想到了除以等于0就够了.至于中间的“取膜”,我没凑齐来,还是不够灵活 package com. ...
- Velocity下面的Velocimacros设置
Velocimacros #macro script element允许模板设计者定义一段可重用的VTL template.Velocimacros广泛用于简单和复杂的行列.Velocimacros的 ...
- BO 与 VO 的属性拷贝 copyProperties(bo,vo)
NewClass extends OldClass : newClass继承自oldClass,属性大多数相同,但是也有新的扩展. beanUtils.copyProperties(oldClas ...
- github 分支操作
1.查看分支 1.查看本地分支 使用git branch命令,如下: $ git branch * master *标识的是你当前所在的分支. 2.查看远程分支 命令如下: git branch -r ...
- 树莓派 Learning 002 装机后的必要操作 --- 01 解决上网问题
树莓派 装机后的必要操作 - 解决上网问题 我的树莓派型号:Raspberry Pi 2 Model B V1.1 装机系统:NOOBS v1.9.2 树莓派 装机后的必要操作 解决上网问题 解决上网 ...
- python 列表中 [[], [], []] 和 3*[[]]差异
问: What's the difference between "[[], [], []]" and "3*[[]]" ? 答: [[], [], []] m ...
- 2.XML实体注入漏洞攻与防
XML实体注入基础 当允许引用外部实体时,通过构造恶意内容,可导致读取任意文件.执行系统命令.探测内网端口.攻击内网网站等危害. 简单了解XML以后,我们知道要在XML中使用特殊字符,需要使用实体字符 ...
- cargo实现自动化部署远程jetty容器(非安全模式)
cargo实现自动化部署应用至远程jetty容器 (非安全模式) 一.准备: WAR包:Deployer Web application for the Jetty remote containers ...
- 网页游戏开发秘笈 PDF扫描版
精选10种常见的游戏类型,透过典型实例,深入剖析游戏引擎及工具的选用技巧,详细讲解每款游戏的制作过程,为快速掌握网页游戏开发提供系统而实用的指南. 网页游戏开发秘笈 目录: 译者序 前 言 导 言 ...