数据结构:
-
首先,我们可以使用
std::tuple<ll, ll, ll>
每个操作有三个元件。对于
q1
在里面
(1, 2)
,我们添加-1作为第三个元素。
-
我们完全模拟给定的
if
s
-
那么,它只是一个有三个条件的for循环。
对于每个操作:
-
如果
q1 == 0
,我们将x附加到
queue[t]
.
-
如果
q1 ==
1.
, we first check if there is a non-empty
队列[t]
, we print out its
正面
-
如果
q1 == 2
,并且有一个非空的
队列[t]
我们
pop()
从…起
队列[t]
.
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
#define fio \
std::ios_base::sync_with_stdio(false); \
std::cin.tie(NULL);
#define ll long long
int main()
{
fio;
ll n = 3, q = 9;
std::vector<std::tuple<ll, ll, ll>> operations = {
{0, 0, 1},
{0, 0, 2},
{0, 0, 3},
{0, 2, 4},
{0, 2, 5},
{1, 0, -1},
{1, 2, -1},
{2, 0, -1},
{1, 0, -1}};
std::vector<std::queue<ll>> queues(n);
for (const auto &[q1, t, x] : operations)
{
if (q1 == 0)
{
queues[t].push(x);
}
else if (q1 == 1)
{
if (!queues[t].empty())
{
std::cout << queues[t].front() << "\n";
}
}
else if (q1 == 2)
{
if (!queues[t].empty())
{
queues[t].pop();
}
}
}
return 0;
}
打印
1.
4.
2.