3185 queue exercises
3185 queue Exercise 1
Time Limit: 1 s space limit: 128000 KB title level: Gold Title Description
Description
Given a queue (initially empty), there are only two types of operations to join and exit. Please output the final line Header element for these operations. Operation explanation: 1 indicates entering the team, 2 indicates leaving the team
Input description
Input Description
N (number of operations)
N operations (if the operation is to join the queue, there will be another element to join the queue)
For details, see the example (input to ensure that the team will not leave when the team is empty)
Output description
Output Description
The final team Header element. If the final team is empty, "impossible!" Is output !" (Without quotation marks)
Sample Input
Sample Input
3
1 2
1 9
2
Sample output
Sample Output
9
Data range and prompt
Data Size & Hint
For 100% of data, elements N ≤ 1000 are positive integers and less than or equal to 100
CATEGORY tag
Tags click here to expand
1 #include<iostream> 2 #include<queue> 3 using namespace std; 4 queue<int>a; 5 int main() 6 { 7 int n; 8 cin>>n; 9 for(int i=1;i<=n;i++)10 {11 int b;12 cin>>b;13 if(b==1)14 {15 int c;16 cin>>c;17 a.push(c);18 }19 else if(b==2)20 {21 a.pop();22 }23 }24 if(a.size()==0)25 {26 cout<<"impossible!";27 }28 else29 {30 cout<<a.front();31 }32 return 0;33 }