• CodeForces


    题目链接:http://codeforces.com/problemset/problem/589/A

    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.

    Examples
    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
    题目大意:输入n,代表有n个字符串,每个字符串分为两部分s1@s2。不需要考虑字母大小写,如果s2是bmail.com结尾的,不需要考虑 . 和第一个+号到@之间的字符。 问你属于同一类的字符串有多少个,按照
    输入顺序输出
    思路:用map来存字符串和它是第几个,当然这里的字符串是指消去了可以消去的字符之后的字符串,用vector来存储答案
    具体看代码
    #include<iostream>
    #include<string.h>
    #include<map>
    #include<cstdio>
    #include<cstring>
    #include<stdio.h>
    #include<cmath>
    #include<math.h>
    #include<algorithm>
    #include<set>
    #include<queue>
    typedef long long ll;
    using namespace std;
    const ll mod=1e9+7;
    const int maxn=2e4+10;
    const int maxk=100+10;
    const int maxx=1e4+10;
    const ll maxe=1000+10;
    #define INF 0x3f3f3f3f3f3f
    #define Lson l,mid,rt<<1
    #define Rson mid+1,r,rt<<1|1
    map<string,int>mp;//用于存储属于同一类的字符串的下标
    vector<string>v[maxn];//存储不同类别的字符串
    char a[maxn][110],b[maxn][110],code[110];
    int main()
    {
        int n,id=0;
        cin>>n;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            strcpy(b[i],a[i]);
            int j=0;
            while(a[i][j]!='')
            {
                a[i][j]=tolower(a[i][j]);//将所有大写转换成小写字母
                j++;
            }
        }
        for(int i=0;i<n;i++)
        {
            int j=0,cnt=0,flag=0;
            while(a[i][j]!='@') {cnt++;j++;}
            strcpy(code,a[i]);
            if(strcmp(a[i]+cnt+1,"bmail.com")==0)
            {
                for(j=0;j<cnt;j++)
                {
                    if(a[i][j]=='+') {flag=j;break;}
                }
    
                int sum=0;
                for(j=0;j<(flag==0?cnt:flag);j++)
                {
                    if(a[i][j]=='.') continue;
                    code[sum++]=a[i][j];
                }
                code[sum]='';//注意要加,结束标志
            }
            if(!mp.count(code))
            {
                mp[code]=id;//如果该类还没有出现过,则存储下来
                v[id].push_back(b[i]);//同时放进v中
                id++;
            }
            else
            {
                v[mp[code]].push_back(b[i]);//该类已经存在了,直接放入
            }
        }
        printf("%d
    ",id);
        for(int j=0;j<id;j++)
        {
            int len=v[j].size();
            printf("%d",len);
            for(int k=0;k<len;k++)
                printf(" %s",v[j][k].c_str());
            printf("
    ");
        }
        return 0;
    }
    当初的梦想实现了吗,事到如今只好放弃吗~
  • 相关阅读:
    问题解决:访问自己搭建网页时出现:此地址使用了一个通常用于网络浏览以外的端口。出于安全原因,Firefox 取消了该请求。
    cracer教程5----漏洞分析(下)
    cracer教程3----信息收集
    linux3
    pwdump7的用法及其hash值解密
    maven scope含义的说明
    Spark2.0协同过滤与ALS算法介绍
    Jmeter压力测试工具安装及使用教程
    过滤器(Filter)与拦截器(Interceptor )区别
    @Value()读取配置文件属性,读出值为null的问题
  • 原文地址:https://www.cnblogs.com/caijiaming/p/9407624.html
Copyright © 2020-2023  润新知