TTTTTTTTTTTTTTTTTT CodeForces 589A Email Aliases 字符串 map

本文介绍了一种用于识别等效电子邮件地址的算法,该算法能够处理包含特定格式规则的电子邮件地址,如忽略大小写、特殊字符处理等,并使用map和vector进行高效的数据管理和输出。

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

A - Email Aliases
Time Limit:2000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u
Submit Status

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 "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.comaddresses, 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, addressesACM.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: addressespolycarp+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.

Sample Input

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
题意:于所有的邮箱,都是由login@domain这样的形式构成,而且字符都是不区分大小写的。 我们有一种特殊类型的邮箱——@bmail.com,这种邮箱除了不区分大小写外—— 1,'@'之前的'.',有等同于无 2,'@'之前的第一个'+'之后的字符可以忽略不计 然后其他字符相同的被认定为邮箱相同。 现在给你n(2e4)个邮箱,让你输出每个邮箱出现的次数与所有这个邮箱的原始串


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MM(a,b) memset(a,b,sizeof(a));
const double eps = 1e-10;
const int  inf =0x7f7f7f7f;
const double pi=acos(-1);
const int maxn=20000+100;

char s[maxn][105];
char s2[maxn][105];
map<string,int> mp;
vector<int> vec[maxn];
int num=0;

void init(int k)
{
    for(int i=1;s[k][i]!='\0';i++)
        if(s[k][i]>='A'&&s[k][i]<='Z') s2[k][i]=tolower(s[k][i]);
        else s2[k][i]=s[k][i];

    int p=1;for(;s[k][p]!='@';p++);
    if(strcmp(s2[k]+p+1,"bmail.com")==0)
    {
        int flag=0,cnt=0;
        for(int i=1;s[k][i]!='\0';i++)
          if((s[k][i]=='.'||flag)&&i<p) continue;
          else if(s[k][i]=='+') flag=1;
          else s2[k][++cnt]=tolower(s[k][i]);
        s2[k][cnt+1]='\0';
    }
    if(!mp[s2[k]+1])
       {num++;
        mp[s2[k]+1]=num;
        vec[num].push_back(k);}
    else  {int kk=mp[s2[k]+1];vec[kk].push_back(k);}
}

int main()
{
   int n;
   while(~scanf("%d",&n))
   {
       MM(s,'\0');MM(s2,'\0');num=0;mp.clear();
       for(int i=1;i<=n;i++)
       {
           scanf("%s",s[i]+1);
           init(i);
       }
       printf("%d\n",num);
       for(int i=1;i<=num;i++)
       {
            printf("%d ",vec[i].size());
            for(int j=0;j<vec[i].size();j++)
            {
                int k=vec[i][j];
                printf("%s ",s[k]+1);
            }
            printf("\n");
       }
       for(int i=1;i<=num;i++) vec[i].clear();
   }
   return 0;
}
分析:比赛时确实做出来了,不过用的哈希,而且并没有充分运用好字符串函数,导致写的时间久,
改进:
1.统计字符串个数不一定用哈希,还可以用map<string,int>;
2.比较字符串可以直接调用strcmp()函数;
3,字母小写转大写可以用toupper(),大写转小写可以用tolower();

 

转载于:https://www.cnblogs.com/smilesundream/p/5683741.html

内容概要:该研究通过在黑龙江省某示范村进行24小时实地测试,比较了燃煤炉具与自动/手动进料生物质炉具的污染物排放特征。结果显示,生物质炉具相比燃煤炉具显著降低了PM2.5、CO和SO2的排放(自动进料分别降低41.2%、54.3%、40.0%;手动进料降低35.3%、22.1%、20.0%),但NOx排放未降低甚至有所增加。研究还发现,经济性和便利性是影响生物质炉具推广的重要因素。该研究不仅提供了实际排放数据支持,还通过Python代码详细复现了排放特征比较、减排效果计算和结果可视化,进一步探讨了燃料性质、动态排放特征、碳平衡计算以及政策建议。 适合人群:从事环境科学研究的学者、政府环保部门工作人员、能源政策制定者、关注农村能源转型的社会人士。 使用场景及目标:①评估生物质炉具在农村地区的推广潜力;②为政策制定者提供科学依据,优化补贴政策;③帮助研究人员深入了解生物质炉具的排放特征和技术改进方向;④为企业研发更高效的生物质炉具提供参考。 其他说明:该研究通过大量数据分析和模拟,揭示了生物质炉具在实际应用中的优点和挑战,特别是NOx排放增加的问题。研究还提出了多项具体的技术改进方向和政策建议,如优化进料方式、提高热效率、建设本地颗粒厂等,为生物质炉具的广泛推广提供了可行路径。此外,研究还开发了一个智能政策建议生成系统,可以根据不同地区的特征定制化生成政策建议,为农村能源转型提供了有力支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值