題意:給定於所有的郵箱,都是由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\n", 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("\n");
}
}
return 0;
}