Description
Polycarp have quite recently learned about email aliases. Of course, he used to suspect so 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 An address from the first character "plus" ('+ ') to character "at" ('@ ') in a login part of email addresses.
Formally, any email address in this problem would 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 tha t the dots split the sequences into non-empty words, consisting only from letters (that's, the "domain" starts from a-letter, ends with a-letter and doesn ' t contain-B or more consecutive dots).
When you compare the addresses, the case of the characters isn ' t taken into consideration. Besides, when comparing the bmail.comaddresses, servers ignore the dots in the login and all characters from the F Irst character "plus" ('+ ') to character "at" ('@ ') in the 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, the domains of these addresses arebmail.com). The next example illustrates the use of character ' [email protected], [email protected] and [ Email protected] also correspond to the same account on the Server [email protected] and [email protected] are not equivalent, because ' + ' is a special character only For bmail.com addresses.
Polycarp has thousands of records in he address Book. Until today, he sincerely thought that's exactly the number of people around the world that he's communicating to. Now he understands this not all distinct records in the Address book represent distinct people.
Help Polycarp bring he 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 EMA Il addresses in Polycarp ' s address Book.
The following n lines contain the email addresses, one per line. It is guaranteed, all of them is correct. All the given lines is distinct. The lengths of the addresses is from 3 to 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 this belong to the i-th Group, separated by a space. It is allowed to print the groups and addresses in each of the 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
4
The code is as follows:
#include <iostream>#include<cstdio>#include<cstring>#include<vector>#include<map>using namespaceStd;typedefLong LongLL;Const intMAXN = 2e4+5;Const DoubleEPS = 1e-7;CharSTR[MAXN];CharS[maxn];map<string,int>Mp;vector<string>VEC[MAXN];intMain () {intN; while(cin>>N) { for(intI=0; i<maxn; i++) vec[i].clear (); Mp.clear (); intTMP =0, ans =0; for(intI=0; i<n; i++) {cin>>str; strcpy (S,STR); intLen =strlen (str); for(intIi=0; ii<len; ii++) { if(str[ii]>='A'&&str[ii]<='Z') Str[ii]= str[ii]+'a'-'A'; if(Str[ii] = ='@') TMP=II; } if(strcmp (str+tmp+1,"bmail.com")==0) { intL =0;///the length after the change for(intj=0; j<tmp; J + +) { if(Str[j] = ='.') Continue; if(Str[j] = ='+') Break; Str[l++] =Str[j]; } for(intj=tmp; STR[J]; J + +) Str[l++] =Str[j]; STR[L]=' /'; } if(Mp.find (str) = = Mp.end ())///Judging there is no sameMP[STR] = ans++; inttt =MP[STR]; Vec[tt].push_back (S); } cout<<ans<<Endl; for(intI=0; i<ans; i++) {cout<<vec[i].size (); for(intj=0; J<vec[i].size (); J + +) cout<<" "<<Vec[i][j]; Puts (""); } } return 0;}
Map and vector---Email Aliases