Codevs 3185 Queue Exercise 1

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.