模拟题加上STL map的应用。
开始竟然想用结构体来处理,后来觉得不仅会占大量空间,并且不好写……
细节见代码。
输入:
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
输出:
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
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<deque>
#include<functional>
#include<iterator>
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<sstream>
#define CPY(A,B)memcpy(A,B,sizeof(A))
typedef long long LL;
typedef unsigned long long uLL;
const int MOD=1e9+7;
const int INF=0x3f3f3f3f;
const LL INFF=0x3f3f3f3f3f3f3f3fLL;
const double EPS=1e-9;
const double OO=1e20;
const double PI=acos (-1.0);
int dx[]= {0,1,0,-1};
int dy[]= {1,0,-1,0};
int gcd (const LL &a,const LL &b) {return b==0?a:gcd (b,a%b);}
using namespace std;
char s[105],t[105];
void Iint (char s[],char S[]) {
strcpy (S,s); int atp=0;//复制一遍,保留原串
for (int i=0; s[i]; i++) {
s[i]=tolower (s[i]);//因为地址不区分大小写
if (s[i]=='@') { atp=i; }//记录@符号的位置
}
if (strcmp (s+atp+1,"bmail.com") ==0) {//只有这个域名才有以下规则
int pos=0;
for (int j=0; j<atp; j++) {
if (s[j]=='.') { continue; }//忽略所有点
if (s[j]=='+') { break; }//‘+’至‘@’符号中间所有字符忽略
s[pos++]=s[j];
}
for (int i=atp; s[i]; i++) { s[pos++]=s[i]; }//拷贝剩下部分
s[pos]=0;
}
}
map<string,int>eadd;
vector<string>ans[20020];
int num[20020];
int main() {
int n,k=0; scanf ("%d",&n);
eadd.clear();
for (int i=1; i<=n; i++) {
scanf ("%s",s);
Iint (s,t);
if (eadd.find (s) ==eadd.end() ) { eadd[s]=++k; }//如果处理后的字符串没出现过,那么就是一个新类
int o=eadd[s]; ++num[o];//请仔细体会 o 的用处
ans[o].push_back (t);//存储原串至同类代码存储区
}
printf ("%d\n",k);
for (int i=1; i<=k; i++) {
printf ("%d",num[i]);//各类别总数
for (int j=0; j<ans[i].size(); j++) {
cout<<" "<<ans[i][j];//输出原串
}
puts ("");
}
return 0;
}