• L2034 口罩发放


    重点在阅读理解能力

    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;
    }
    
  • 相关阅读:
    如何在Oracle官网下载java的JDK最新版本和历史版本
    屏幕录制专家【Bandicam】
    Bandicam下载 + 破解
    华为荣耀7i手动更改DNS,提高网页加载速度
    SQL中使用GROUP BY注意事项
    JavaScript数据类型判断
    React.lazy和Suspense组合实现组件懒加载
    使用React+TypeScript构建自己的组件库
    leetcode-0101 对称二叉树
    leetcode-0543 二叉树的直径
  • 原文地址:https://www.cnblogs.com/ZhengLijie/p/16152365.html
Copyright © 2020-2023  润新知