题在这儿
参考:
https://www.cnblogs.com/ctyakwf/p/12465481.html
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 8;
const int inf = 0x3f3f3f3f;
#define PI 3.14159
struct peo
{
string name_first, name_last;
string phone[1008];
string email[1008];
int sum_pho, sum_ema;
}s[1008];
bool cmp(string a, string b)
{
return a < b;
}
map<string, int> m;
int main()
{
int n, d = 1;
while(~scanf("%d", &n) && n)
{
m.clear();
for(int i = 0; i < 1008; i++)
s[i].sum_ema = s[i].sum_pho = 0;
string first, last, str;
int f = 1;//几个人
for(int i = 1; i <= n; i++)
{
cin >> first >> last >> str;
string name = last + first;//名字排序
if(!m[name])//判断有没有这人
{
m[name] = f;
s[f].name_first = first;
s[f].name_last = last;
int ff = str.find("@");
if(ff == string::npos)
{
int sp = s[f].sum_pho;
s[f].phone[sp] = "(" + str.substr(0, 3) + ")" + str.substr(3, 3) + "-" + str.substr(6);
s[f].sum_pho++;
}
else
{
int se = s[f].sum_ema;
s[f].email[se] = str;
s[f].sum_ema++;
}
f++;
}
else
{
int sum = m[name];
int ff = str.find("@");
if(ff == string::npos)
{
int sp = s[sum].sum_pho;
s[sum].phone[sp] = "(" + str.substr(0, 3) + ")" + str.substr(3, 3) + "-" + str.substr(6);
s[sum].sum_pho++;
}
else
{
int se = s[sum].sum_ema;
s[sum].email[se] = str;
s[sum].sum_ema++;
}
}
}
map<string, int>::iterator it;
printf("Contact list #%d:\n", d++);
for(it = m.begin(); it != m.end(); it++)
{
int sum_s = it->second;
cout << s[sum_s].name_first << ' ' << s[sum_s].name_last << endl;
cout << "Phone:" << endl;
sort(s[sum_s].phone, s[sum_s].phone + s[sum_s].sum_pho, cmp);
for(int j = 0; j < s[sum_s].sum_pho; j++)
cout << s[sum_s].phone[j] << endl;
cout << "E-Mail:" << endl;
sort(s[sum_s].email, s[sum_s].email + s[sum_s].sum_ema, cmp);
for(int k = 0; k < s[sum_s].sum_ema; k++)
cout << s[sum_s].email[k] << endl;
cout << "###" << endl;
}
cout << endl;
}
}