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 "[email protected]", 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 [email protected] and [email protected] correspond to the same account. Similarly, addresses [email protected] and [email protected] 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 [email protected], [email protected] and [email protected] also correspond to the same account on the server bmail.com. However, addresses [email protected] and [email protected] 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

Input

6[email protected][email protected][email protected][email protected][email protected][email protected]

Output

42 [email protected] [email protected] 2 [email protected] [email protected] 1 [email protected] 1 [email protected] 题意:有两种邮件第一种:@bmail 第二种L:@bmain.xxx。对于第一种邮件格式我们要求在@前的 . 忽略,对于@前第一个出现的+后面的内容直到@全部删除,给你n个邮件地址,让你把它们分组,并把每组所包含的邮件数 和 邮件都打印出来。分析: map搞。
 1 /*************************************************************************
 2     > File Name: 365A.cpp
 3     > Author:
 4     > Mail:
 5     > Created Time: 2016年07月29日 星期五 20时54分32秒
 6  ************************************************************************/
 7
 8 #include<iostream>
 9 #include<bits/stdc++.h>
10 using namespace std;
11 const int maxn = 2e4 + 7;
12 map<string,int> mp;
13 map<string,int> :: iterator it;
14 int num[maxn];
15 vector<string> a[maxn];
16 char cnt[] ={"bmail.com"};
17 char str[105],str1[105];
18
19 int main()
20 {
21     int n;
22     cin >> n;
23     int id = 0;
24     mp.clear();
25     while(n--)
26     {
27         cin >> str;
28         strcpy(str1,str);
29         int st;
30         for(int i = 0; str1[i]; i++)
31         {
32             str1[i] = tolower(str1[i]);
33             if(str1[i] == ‘@‘) st = i;
34         }
35         if(strcmp(str1 + st + 1,cnt) == 0)
36         {
37             int t = 0;
38             for(int i = 0; i< st; i++)
39             {
40                 if(str1[i] == ‘.‘) continue;
41                 if(str1[i] == ‘+‘) break;
42                 str1[t++] = str1[i];
43             }
44             for(int i = st; str1[i];i++)
45             {
46                 str1[t++] = str1[i];
47             }
48             str1[t] = 0;
49         }
50         if(mp.find(str1) == mp.end()) mp[str1] = ++id;
51         int ss = mp[str1];
52         ++num[ss];
53         a[ss].push_back(str);
54     }
55     cout << id << endl;
56     for(int i = 1; i<= id; i++)
57     {
58         cout << num[i] << endl;
59         for(int j = 0; j< a[i].size(); j++) cout << ‘ ‘ << a[i][j];
60         cout << endl;
61     }
62     return 0;
63 }
				
时间: 2024-08-29 15:42:15

codeforces 589A Email Aliases(map)的相关文章

CodeForce 589A Email Aliases

Email Aliases 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 (charact

CodeForces 589 Email Aliases (匹配,水题)

题意:给定于所有的邮箱,都是由[email protected]这样的形式构成,而且字符都是不区分大小写的. 我们有一种特殊类型的邮箱——@bmail.com, 这种邮箱除了不区分大小写外—— 1,'@'之前的'.',有等同于无 2,'@'之前的第一个'+'之后的字符可以忽略不计 然后其他字符相同的被认定为邮箱相同. 现在给你 n 个邮箱,让你输出每个邮箱出现的次数与所有这个邮箱的原始串. 析:没什么好说的,就是先判断不是@bmail.com,然后再按要求去点,去+和@之间的值,然后一个一个的比

CodeForces 567C. Geometric Progression(map 数学啊)

题目链接:http://codeforces.com/problemset/problem/567/C C. Geometric Progression time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Polycarp loves geometric progressions very much. Since he was on

CodeForces - 670C Cinema (map&amp;模拟)水

CodeForces - 670C Cinema Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of th

CodeForces - 589A(字符串处理)

题目链接:http://codeforces.com/problemset/problem/589/A 题目大意:给定n个邮件地址,任何电子邮件地址都将显示为"login @ domain",其中: 1.a"login"是一个由非空的小写和大写字母序列以及点('.')和加号('+')组成的序列,从字母开始;2.a"domain"是一个由非空的小写和大写字母和点组成的序列,因为点将序列分成非空单词,仅由字母组成(即"domain"

Codeforces 567C - Geometric Progression - [map维护]

题目链接:https://codeforces.com/problemset/problem/567/C 题意: 给出长度为 $n$ 的序列 $a[1:n]$,给出公比 $k$,要求你个给出该序列中,长度为 $3$ 的等比子序列的数目. 题解: 首先倒着遍历,用map记录曾经出现过的每个数字的出现次数,然后再用另一个map来记录曾经出现过的所有满足 $(x,kx)$ 的二元组的数目,最后就直接维护答案即可. AC代码: #include<bits/stdc++.h> #define IO (i

codeforces 589a(构造的字符串后,最后要加终止符,,,)

模拟注意细节,没什么好说的#include <cstdio> #include <cstring> #include <vector> #include <algorithm> #include <iostream> #include <map> #include <queue> #include <stack> #include <cmath> //#pragma comment(linker,

CodeForces - 589A(二分+贪心)

题目链接:http://codeforces.com/problemset/problem/589/F 题目大意:一位美食家进入宴会厅,厨师为客人提供了n道菜.美食家知道时间表:每个菜肴都将供应. 对于第i道菜肴,他知道时间ai和bi的两个整数时刻(从宴会开始的几秒钟内) - ai为该菜端出来的时间,bi为该菜端走的时间(ai <BI).例如,如果ai = 10且bi = 11,那么第i个菜肴可在一秒钟内进食. 菜肴数量非常大,所以只要菜肴可以吃(即,在大厅里),它就无法用完. 美食家想要尝试每

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 (character