7-13 口罩发放 (10 分)

7-13 口罩发放 (10)
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <unordered_map>
using namespace std;

struct Record{
	string name, ID;
	bool state;
	string tim;
	int num; 	// 在当天的第几条记录 
}; 

Record r[10010];
Record w[10010];
int d, p, t, s, tot;
unordered_map <string, int> g;

bool checkID(string s)
{
	if (s.size() != 18) return false;
	for (int i=0; i<18; i++)
		if (s[i] < '0' || s[i] > '9') return false;
	
	return true; 
}

bool cmp(Record a, Record b) {
	if (a.tim < b.tim) return true;
	else if (a.tim == b.tim && a.num < b.num) return true;
	return false;
}

int main()
{
	cin >> d >> p;
	for (int day = 1; day <= d; day++)
	{
		cin >> t >> s;
		string a, b, c;
		bool st;
		int cnt = 0;
		for (int i=1; i<=t; i++) {
			cin >> a >> b >> st >> c;
			if (checkID(b)) {	// 检查身份证是否合法 
				cnt++;
				r[cnt] = {a, b, st, c, cnt}; 
			}
			if (st == 1) {
				tot++;
				w[tot] = r[cnt];
			}
		}
		sort(r+1, r+cnt+1, cmp);
		
		for (int i=1; i<=cnt; i++)
		{
			string cid = r[i].ID;
			if (g.count(cid) == 0 && s) {
				// cout << s << " --- " ;
				printf("%s %s\n", r[i].name.c_str(), r[i].ID.c_str());
				g[cid] = day;
				s--;
			} else {
				int lastDay = g[cid];
				//cout << "name last day : " << r[i].name << " " << lastDay << endl; 
				if (day - lastDay > p && s) {
					// cout << s << " --- ";
					printf("%s %s\n", r[i].name.c_str(), r[i].ID.c_str());
					s--;
				}
			}
			if (!s) break;
		}
	}
	for (int i=1; i<=tot; i++) 
	{
		bool printed = false;
		for (int j=1; j<i; j++) 
			if (w[j].ID == w[i].ID) {
				printed = true;
				break;
			}
		if(!printed) printf("%s %s\n", w[i].name.c_str(), w[i].ID.c_str());
	}
	return 0;	
} 

  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值