CodeForces 589A Email Aliases (匹配,水题)

题意:给定于所有的邮箱,都是由login@domain这样的形式构成,而且字符都是不区分大小写的。 我们有一种特殊类型的邮箱——@bmail.com,

这种邮箱除了不区分大小写外—— 1,'@'之前的'.',有等同于无 2,'@'之前的第一个'+'之后的字符可以忽略不计 然后其他字符相同的被认定为邮箱相同。 

现在给你 n 个邮箱,让你输出每个邮箱出现的次数与所有这个邮箱的原始串。

析:没什么好说的,就是先判断不是@bmail.com,然后再按要求去点,去+和@之间的值,然后一个一个的比较即可,这个题有坑,第一次WA在第54组数据上了,
就是我把@后面的点去了,这个是不能去的,别的都正常。后来我看这个总数据,一共就54组。。。。。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <stack>
using namespace std ;

typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 2e4 + 5;
const int mod = 1e9 + 7;
const char *mark = "+-*";
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
int n, m;
inline bool is_in(int r, int c){
    return r >= 0 && r < n && c >= 0 && c < m;
}
struct node{
    string s;
    string chage;
    int id;
};
node a[maxn];
bool cmp(const node &lhs, const node &rhs){
    return lhs.chage < rhs.chage || (lhs.chage == rhs.chage && lhs.id < rhs.id);
}
bool cmp1(const node &lhs, const node &rhs){
    return lhs.id < rhs.id;
}
vector<int> ans[maxn];

int main(){
    while(scanf("%d", &n) == 1){
        string s;
        for(int i = 0; i < n; ++i){
            cin >> a[i].s;
            a[i].id = i;
            ans[i].clear();
        }
        for(int i = 0; i < n; ++i){
            string t;
            if(a[i].s.size() < 10) ;
            else{
                t = a[i].s.substr(a[i].s.size()-10, 10);
                    for(int i = 0; i < 10; ++i)
                        t[i] = towlower(t[i]);
            }

            if(t == "@bmail.com"){
                bool ok = false;
                bool ok1 = false;
                for(int j = 0; j < a[i].s.size(); ++j){
                    if(a[i].s[j] == '@')  ok = false, ok1 = true;
                    else if(a[i].s[j] == '+')  ok = true;
                    if((a[i].s[j] == '.' && !ok1) || ok) continue;
                    a[i].chage.push_back(towlower(a[i].s[j]));
                }

            }
            else{
                for(int j = 0; j < a[i].s.size(); ++j){
                    a[i].chage.push_back(towlower(a[i].s[j]));
                }
            }
        }
        sort(a, a+n, cmp);
        int cnt = 0;
        ans[0].push_back(a[0].id);
        for(int i = 1; i < n; ++i){
            if(a[i].chage == a[i-1].chage) ans[cnt].push_back(a[i].id);
            else ans[++cnt].push_back(a[i].id);
        }

        sort(a, a+n, cmp1);
        printf("%d
", cnt+1);
        for(int i = 0; i <= cnt; ++i){
            printf("%d", ans[i].size());
            for(int j = 0; j < ans[i].size(); ++j){
                printf(" %s", a[ans[i][j]].s.c_str());
            }
            printf("
");
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/dwtfukgv/p/5757811.html