Title Description
Description
Given a queue (initially empty), only two operations are queued and out of the team, now give these operations to output the final team header element. Operation Explanation: 1 means queue, 2 indicates the team
Enter a description input
Description
N (number of operations)
n Operations (there will be a queue element after the queue)
See Example (Input guarantee team will not be out of the team when empty)
Outputs description output
Description
Final team head element, if the final team is empty, output "impossible!" (without quotation marks)
Sample input to
sample
3
1 2
1 9
2
Sample output sample
outputs
9
Data
size & Hint
For 100% of data n≤1000 elements are positive integers and less than or equal to 100
Code:
#include <iostream>
using namespace Std;
int a[1010],n;
int main ()
{
int x,y,head=0,tail=0;
cin>>n;
for (int i=1;i<=n;i++)
{
cin>>y;
if (y==1)
{
cin>>x;a[tail]=x;
tail++;
}
if (y==2)
{
head++;
}
}
if (head==tail) cout<< "impossible!";
else cout<<a[head];
return 0;
}
Codevs 3185 Queue Exercise 1