Descriptionios
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. c++
Formally, any email address in this problem will look like "login@domain", where:dom
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.ide
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.ui
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.this
Help Polycarp bring his notes in order by merging equivalent addresses into groups.spa
Inputcode
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.orm
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.server
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搞。
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 }