其他分享
首页 > 其他分享> > L2-034 口罩发放

L2-034 口罩发放

作者:互联网

重点在阅读理解能力

  1. 身份证号必须是18位数字,话说平时咱们身份证也可以带个X啥的啊。
  2. 合法状态就是只要身份证合格就行,一开始我还想是它犯病,然后申请了口罩才算一个合法记录。
  3. 后边输出状态为1的人,一定要按照每个人犯病顺序输出,也就是说如果某个人一开始没犯病,后边犯病了,那取它在后边的顺序。
    这样模拟下来就没有问题了
#include <bits/stdc++.h>

using namespace std;

struct people {
    string name, idcard;
    int state;
    string submitTime;
    int idx;
    bool operator< (const people& other) const {
        if (submitTime == other.submitTime) return idx < other.idx;
        return submitTime < other.submitTime;
    }
};

const int N = 45;
vector<people> dayilyrecords[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int d, p;
    cin >> d >> p;   
    map<string, string> idcard_name;
    vector<string> haveRecordsAndst1; 
    map<string, int> lastbuy;
    for (int i = 1; i <= d; i++) {
        int t, s;
        cin >> t >> s;
        for (int j = 1; j <= t; j++) {
            string name, idcard;
            int state;
            string submitTime;
            int idx = j;
            cin >> name >> idcard >> state >> submitTime;
            
            if (idcard.size() != 18) continue;
            bool checkisdigit = true;
            for (int _ = 0; _ < idcard.size(); _++) {
                if (!isdigit(idcard[_])) {
                    checkisdigit = false;
                    break;
                }
            }
            if (!checkisdigit) continue;
            
            idcard_name[idcard] = name;
            dayilyrecords[i].push_back({name, idcard, state, submitTime, idx});
            if (state == 1) haveRecordsAndst1.push_back(idcard); //只要有记录就得输出
        }
        sort(dayilyrecords[i].begin(), dayilyrecords[i].end());
        int limit = 0;
        for (int j = 0; j < dayilyrecords[i].size(); j++) {
            if (limit >= s) break;
            string name = dayilyrecords[i][j].name, idcard = dayilyrecords[i][j].idcard;
            int state = dayilyrecords[i][j].state;
            //没有买过
            if (!lastbuy.count(idcard) || i >= lastbuy[idcard] + p + 1) {
                lastbuy[idcard] = i;
                limit++;
                cout << name << " " << idcard << "\n";
            } 
        }
    }

    map<string, bool> haveoutput;
    for (int i = 0; i < haveRecordsAndst1.size(); i++) {
        if (haveoutput[haveRecordsAndst1[i]] == 0) {
            haveoutput[haveRecordsAndst1[i]] = 1;
            cout << idcard_name[haveRecordsAndst1[i]] << " " << haveRecordsAndst1[i] << "\n";
        }
    }

    return 0;
}

标签:口罩,name,int,dayilyrecords,idcard,submitTime,state,L2,034
来源: https://www.cnblogs.com/ZhengLijie/p/16152365.html