UCF “Practice” Local Contest — Aug 24, 2013 D.Cell Phone Contacts(模拟/map)

题在这儿
参考:
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;
	 }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值