CodeForces - 589A(字符串)

本文介绍了一种处理电子邮件别名的方法,特别关注了bmail.com服务器如何处理登录部分的点和加号字符,以及如何将等效的电子邮件地址分组。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


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;
}
基于Spring Boot搭建的一个多功能在线学习系统的实现细节。系统分为管理员和用户两个主要模块。管理员负责视频、文件和文章资料的管理以及系统运营维护;用户则可以进行视频播放、资料下载、参与学习论坛并享受个性化学习服务。文中重点探讨了文件下载的安全性和性能优化(如使用Resource对象避免内存溢出),积分排行榜的高效实现(采用Redis Sorted Set结构),敏感词过滤机制(利用DFA算法构建内存过滤树)以及视频播放的浏览器兼容性解决方案(通过FFmpeg调整MOOV原子位置)。此外,还提到了权限管理方面自定义动态加载器的应用,提高了系统的灵活性和易用性。 适合人群:对Spring Boot有一定了解,希望深入理解其实际应用的技术人员,尤其是从事在线教育平台开发的相关从业者。 使用场景及目标:适用于需要快速搭建稳定高效的在线学习平台的企业或团队。目标在于提供一套完整的解决方案,涵盖从资源管理到用户体验优化等多个方面,帮助开发者更好地理解和掌握Spring Boot框架的实际运用技巧。 其他说明:文中不仅提供了具体的代码示例和技术思路,还分享了许多实践经验教训,对于提高项目质量有着重要的指导意义。同时强调了安全性、性能优化等方面的重要性,确保系统能够应对大规模用户的并发访问需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值