国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

CodeForces - 589A(字符串)

2019-11-08 18:22:36
字體:
來源:轉載
供稿:網友

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.

Example 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 Output 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.com這個域名的郵箱地址服務器會忽略@之前的.和+號和@之間的所有字符,所以匹配到這個域名的字符串就得處理掉這些東西,然后用map/</string,vector >來映射處理后的字符串和答案數組。

#include<iostream>#include<stdio.h>#include<algorithm>#include<string.h>#include<string>#include<map>#include<set>#include<vector>using namespace std;string add[20010];int n;map<string,vector<int> > m; int main(){ scanf("%d",&n); m.clear(); for(int i=0;i<n;i++){ cin>>add[i]; int len=add[i].length(); string cnt=add[i]; for(int j=0;j<len;j++){//xiaoxie if(cnt[j]>='A'&&cnt[j]<='Z'){cnt[j]+=32;} } string newo=""; if(len>9&&(cnt.find("@bmail.com")==len-10)){//judge int plus=0; for(int j=0;j<len;j++){ if(cnt[j]=='+'){plus=1;} else if(cnt[j]=='@'){plus=2;} if(plus==0&&cnt[j]!='.'){newo+=cnt[j];} else if(plus==2){newo+=cnt[j];} } } else{//no newo=cnt; } map<string,vector<int> >::iterator it =m.find(newo); if(it==m.end()){m[newo].clear(); m[newo].push_back(i);} else{it->second.push_back(i);} } int a=m.size(); printf("%d/n",a); for(map<string,vector<int> >::iterator it =m.begin();it!=m.end();it++){ int b=it->second.size(); printf("%d ",b); for(int i=0;i<b;i++){ cout<<add[it->second[i]]; if(i<b-1){printf(" ");} } printf("/n"); }return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 牟定县| 赞皇县| 潜江市| 大港区| 四子王旗| 凉山| 竹溪县| 宝丰县| 平邑县| 信丰县| 肥城市| 广河县| 乌恰县| 曲阳县| 嘉义县| 连州市| 镇江市| 旺苍县| 黄梅县| 柏乡县| 昌邑市| 旬邑县| 开封县| 连云港市| 翁源县| 综艺| 英超| 潜山县| 广丰县| 高淳县| 图们市| 寻乌县| 大洼县| 普格县| 嘉禾县| 阜城县| 花垣县| 永新县| 浮梁县| 昆山市| 保定市|