L2-034 口罩发放 (25 分)注释详解

#include<bits/stdc++.h>
using namespace std;

struct per {
	string a;
	string b;
	int t;
	int idx;
};

const int N = 1e5;

vector<struct per> v[N];
vector<struct per> ans;
map<string,int> mp,flag;
struct per p;

int dd,pp;
int t,s;

//判断身份是否能够给口罩 
bool jg(string s,int day){
	if(mp[s] == 0) return true;
	if(day - mp[s] > pp) return true;
	return false;
}

//判断身份证是否合法 
bool check(string s){
	if(s.size() != 18) return false;
	for(int i=0;i<s.size();i++) if(!isdigit(s[i])) return false;
	return true;
}


//排序 
bool cmp(struct per a,struct per b){
	if(a.t != b.t) return a.t < b.t;
	return a.idx < b.idx;
}


int main(){
	
	cin>>dd>>pp;
	for(int i=1;i<=dd;i++){
		cin>>t>>s;
		for(int j=1;j<=t;j++){
			cin>>p.a>>p.b;
			int hh,mm,c;
			scanf("%d %d:%d",&c,&hh,&mm);
			p.t = hh*60 + mm;
			p.idx = j;
			if(c == 1 && !flag[p.b] && check(p.b)) {
				flag[p.b] = 1;
				ans.push_back(p);
			}
			
			v[i].push_back(p);
			
			
		}
		
		
		sort(v[i].begin(),v[i].end(),cmp);
		
		for(int w=0;w<v[i].size() && s;w++){
			string temp = v[i][w].b;
			
			if(check(temp) && jg(temp,i)){
				cout<<v[i][w].a<<" "<<v[i][w].b<<endl;
				s--;
				mp[temp] = i;//更新得到口罩的日期 
			}
		}
			
		
	}
		for(int i=0;i<ans.size();i++){
			cout<<ans[i].a<<" "<<ans[i].b<<endl;
		}
		
	return 0;
}
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值