打印队列有两个属性,一个是优先级一个是位置,可以写一个结构体存储这些信息再利用queue的特性完成本题
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
const int maxn = 100;
struct Coor
{
int priority;
int position;
} co[maxn];
queue<Coor> line;
void main()
{
int n;
int a;
cin >> n;
for(int i = 0; i < n; i++)
{
cin >> a;
co[i].priority = a;
co[i].position = i;
line.push(co[i]);
}
int positon;
cin >> positon;
int max = 0;
bool is_print = false;
int count = 0;
while(!is_print)
{
if(max == 0)
{
for(int i = 0; i < n; i++)
{
if(co[i].priority != 0)
{
if(max < co[i].priority) max = co[i].priority;
}
}
}
Coor co1 = line.front();
if(co1.priority == max)
{
if(co1.position == positon)
{
count++;
is_print = true;
}
else
{
co[co1.position].priority = 0;
max = 0;
line.pop();
count++;
}
}
else
{
line.pop();
line.push(co1);
}
}
cout << count << endl;
}