cf589A 模拟

题目大意:解析电子邮箱地址并分组,不区分大小写,只有域名是bmail.com才有特殊规则。。。。。。。。
#include <bits/stdc++.h>

using namespace std;

struct node
{
    string add;
    int id;
    friend bool operator <(node n1 , node n2)
    {
        if(n1.add == n2.add) return n1.id > n2.id;
        else return n1.add < n2.add;
    }
};

string str[20005];
map<node , int>M;
map<node , int>::iterator it;
map<string , int>M2;
map<string , int>::iterator it2;
int main()
{
    int n;
    while(scanf("%d" , &n) != EOF)
    {
        M.clear();
        M2.clear();
        char tmp[105];
        for(int i = 0 ; i < n ; i ++)
        {
            scanf("%s" , tmp);
            str[i] = tmp;
        }
        for(int i = 0 ; i < n ; i ++)
        {
            string str2 = "";
            int flag = 0;
            int flag2 = 0;
            int len = str[i].length();
            int pos = str[i].find('@');
            string str3 = str[i].substr(pos + 1, len);
           // cout << str3 << endl;
            int len3 = str3.length();
            for(int j = 0 ; j < len3 ; j ++ )
            {
                if(str3[j] >= 'A' && str3[j] <= 'Z') str2 += (str3[j] - 'A' + 'a');
                else str2 += str3[j];
            }
          //  cout << str2 << endl;
            if(str2 == "bmail.com") flag2 = 1;
            str2 = "";
            for(int j = 0 ; j < len ; j++)
            {
                if(str[i][j] == '@') flag = 1;
                if(!flag && str[i][j] == '.')
                {
                    if(flag2) continue;
                    else str2 += str[i][j];
                }
                else if(!flag && str[i][j] == '+')
                {
                    if(flag2 == 0)
                    {
                        if(str[i][j] >= 'A' && str[i][j] <= 'Z') str2 += (str[i][j] - 'A' + 'a');
                        else str2 += str[i][j];
                    }
                    else
                    {
                        while(str[i][j] != '@') j++;
                        j--;
                    }
                }
                else if(!flag)
                {
                    if(str[i][j] >= 'A' && str[i][j] <= 'Z') str2 += (str[i][j] - 'A' + 'a');
                    else str2 += str[i][j];
                }
                if(flag)
                {
                    if(str[i][j] >= 'A' && str[i][j] <= 'Z') str2 += (str[i][j] - 'A' + 'a');
                    else str2 += str[i][j];
                }
            }
          //  cout << str2 << endl;
            node temp;
            temp.add = str2;
            temp.id = i;
            M[temp]++;
            M2[str2]++;
        }
        printf("%d\n" , M2.size());
        it = M.begin();
        for(it2 = M2.begin(); it2 != M2.end() ; it2 ++)
        {
            printf("%d " , it2 -> second);
            for(int i = 0; it != M.end() , i < it2 -> second; it ++ , i ++)
            {
                node tt = it -> first;
                cout << str[tt.id];
                if(i != it2 -> second - 1) printf(" ");
            }
            printf("\n");
        }
    }
}

你可能感兴趣的:(cf589A 模拟)