nyoj1117 Egg Queue (double-ended queue, deque)

Source: Internet
Author: User

    • topic 1117
    • topic information
    • run result
    • line
    • discussion area
Egg Queue time limit: +Ms | Memory Limit:65535KB Difficulty:1
Describe

A queue is formed by placing two chopsticks parallel together. Put the numbered eggs between the two chopsticks called the queue (push), the chopsticks between the eggs out called to make a team (pop). But these two ways have a special definition, for the team, only the eggs from the tail of the queue into the, for out of the queue, only the eggs from the head outward to the eggs out.

Join ① and ② in the queue:

Head ____________ Tail  _____________                           ______________

←①←②                   ①← ② ①②

 ______________   _____________                           ______________

①, ② out of the team:

Head ____________ Tail  ______________                          ______________

←①←②                   ①←     ②                    ①②

______________     ______________                          ______________


Input
The first line enters a number T, which indicates that there is a T group of data
The second line enters a number n, which indicates that there are N (n<=10) operations
Next n rows, one action per line, push indicates that an egg numbered x is placed in a queue, and a pop represents an egg taking the head of the queue.
The data input is guaranteed to be legal, there will be no team operation when there are no eggs in the queue!
Output
after the output n operation, the number of the egg in the queue, if no eggs, the output "no eggs!" (excluding quotation marks) contains one row for each set of outputs.
Sample input
23push 1 Push 2push 32push 1pop
Sample output
1 2 3no eggs!
double-ended queue (deque) <deque>

Arrays of continuously stored pointers to different elements <deque>

Deque<int>c

C.pop_back () deletes the last data.

C.pop_front () deletes header data.

C.push_back (elem) adds a data to the tail.

C.push_front (elem) inserts a data in the head.

C.clear () Removes all data from the container.

C.front () returns a data back to the ground.

C.back () returns the last data without checking to see if the data exists.

C.size () returns the number of actual data in the container.

C.empty () Determines whether the container is empty.

C[i] equivalent to c.at (i);

Want to see the details of the click to open the link

#include <stdio.h> #include <string.h> #include <queue>using namespace Std;int main () {Deque<int >s;char str[5];int t,n;scanf ("%d", &t), while (t--) {scanf ("%d", &n), for (int i=0;i<n;i++) {memset (str,0, sizeof (str)); scanf ("%s", str), if (strcmp (str, "push") ==0) {int x;scanf ("%d", &x); S.push_back (x);} Elses.pop_front ();} if (!s.empty ()) {printf ("%d", S.front ()); S.pop_front (); while (!s.empty ()) printf ("%d", S.front ()), S.pop_front (); printf ("\ n");} elseprintf ("no eggs!\n");} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

nyoj1117 Egg Queue (double-ended queue, deque)

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.