题目:
解答:
vector<pair<int, int>> parsedict(string str)
{
vector<int> res = str2vint(str, ' ');
vector<pair<int, int>> ret;
for (int i = 0; i < res.size();i++)
{
if (i%2 == 1)
{
ret.push_back(make_pair(res[i - 1],res[i]));
}
}
return ret;
}
vector<pair<int, string>> parsedict2(string str)
{
vector<string> res = str2vstr(str, ' ');
vector<pair<int, string>> ret;
for (int i = 0; i < res.size(); i++)
{
if (i % 2 == 1)
{
ret.push_back(make_pair(stoi(res[i - 1]), res[i]));
}
}
return ret;
}
bool cmp6(pair<int, string>a, pair<int, string>b)
{
return a.first < b.first;
}
bool cmp7(int a,int b)
{
return a > b;
}
void parse28()
{
string str1;
string str2;
getline(cin, str1);
getline(cin, str2);
vector<pair<int, string>> msgq = parsedict2(str1);
vector<pair<int, int>> userq = parsedict(str2);
sort(msgq.begin(), msgq.end(), cmp6);
int usrnum = userq.size();
vector<vector<string>> res(usrnum, vector<string>());
int timemax = msgq.back().first;
vector<int> subuser;
int order = 0;
for (int i =0;i <= timemax;i++)
{
string msg;
for (int j = 0; j < usrnum; j++)
{
// sub
if (userq[j].first == i)
{
subuser.push_back(j);
}
//unsub
if (userq[j].second == i)
{
for (int k = 0; k < subuser.size(); k++)
{
if (subuser[k] == j)
{
subuser.erase(subuser.begin() + k);
}
}
}
}
sort(subuser.begin(), subuser.end(),cmp7);
if (msgq[order].first == i)
{
msg = msgq[order].second;
if (subuser.size()>0)
{
res[subuser[0]].push_back(msg);
}
order++;
}
}
for (auto it : res)
{
for (auto it2: it)
{
cout << it2 << ' ';
}
cout << endl;
}
}
int main()
{
parse28();
return 0;
}