L2-034 口罩发放

//注意理解可以包含前导0的意思
#include<bits/stdc++.h>
using namespace std;
struct patient{ 
    string name,id,time;//姓名,身份证号,申请时间
    int heal,order;//身体情况,列表中出现顺序   
}a;
map<string,int>card;//绑定身份证号和可申请的日期
vector<patient>v;
map<string,string>law;//绑定身份证号和姓名
vector<string>mm;//记录有相关症状的人
bool cmp(patient c,patient d){//排序方式
    if(c.time!=d.time) return c.time<d.time;//先比时间
    else return c.order<d.order;//再比在列表中出现顺序
}
int check(string w)//判断身份证是否合法
{
    for(int t=0;t<18;t++){
        if(!isdigit(w[t]))return 0;
    }
    return 1;
}
int main()
{
   int day,p,rep,peo;
   cin>>day>>p;
    for(int t=1;t<=day;t++){
        cin>>rep>>peo;
        for(int j=1;j<=rep;j++){
          cin>>a.name>>a.id>>a.heal>>a.time; 
          a.order=j;
          if(a.id.length()==18&&check(a.id)){//判断身份证是否合法
              if(a.heal&&find(mm.begin(),mm.end(),a.id)==mm.end()){//对发烧的人进行去重并按序输出
                  law[a.id]=a.name;
                  mm.push_back(a.id);
              }
              v.push_back(a);
          }
        }
        sort(v.begin(),v.end(),cmp);//排序
        for(auto j:v){
            if(peo==0) break;//口罩以发完
            if(card.find(j.id)==card.end()||card[j.id]<=t){
                cout<<j.name<<" "<<j.id<<endl;
                card[j.id]=t+p+1;//更新可申请日期          
                --peo;
            }
        }
        v.clear();//清空
    }
    for(auto j:mm)cout<<law[j]<<" "<<j<<endl;
}

复杂模拟题

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值