模拟题第一次写测试点5挂了,发现一个坑点,身份证是唯一的,而姓名不是,所以要以身份证为基准
代码:
#include <bits/stdc++.h>
using namespace std;
unordered_map <string, int> mp, st;
vector <string> res;
unordered_map <string, string> sf;
struct node {
string name, idcard;
int state, hh, mm, order;
};
bool cmp (node a, node b)
{
if (a.hh == b.hh)
{
if (a.mm == b.mm)
return a.order < b.order;
return a.mm < b.mm;
}
return a.hh < b.hh;
}
bool check (string id)
{
if (id.length () != 18) return false;
for (int i = 0; i < id.length (); i ++)
{
if (id[i] < '0' || id[i] > '9')
return false;
}
return true;
}
int main ()
{
int d, p;
cin >> d >> p;
for (int k = 1; k <= d; k ++)
{
int t, s; cin >> t >> s;
node peo[1010];
for (int i = 1; i <= t; i ++)
{
cin >> peo[i].name >> peo[i].idcard >> peo[i].state;
scanf ("%d:%d", &peo[i].hh, &peo[i].mm);
peo[i].order = i;
sf[peo[i].idcard] = peo[i].name;
if (check (peo[i].idcard) && peo[i].state == 1)
res.push_back (peo[i].idcard);
}
sort (peo + 1, peo + 1 + t, cmp);
for (int i = 1; i <= t; i ++)
{
if (mp[peo[i].idcard] == 0 || k > mp[peo[i].idcard])
{
if (check (peo[i].idcard) && s > 0)
{
s --;
mp[peo[i].idcard] = k;
mp[peo[i].idcard] += p;
cout << peo[i].name << " " << peo[i].idcard << "\n";
}
if (s == 0) break;
}
}
}
for (int i = 0; i < (int)res.size (); i ++)
{
if (st[res[i]] == 0)
{
cout << sf[res[i]] << " " << res[i] << "\n";
st[res[i]] = 1;
}
}
return 0;
}