(Hdu step 8.1.1) Acboy needs your help again! (Basic use of stacks and queues in STL)

Source: Internet
Author: User

Topic:

Acboy needs your help again!
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): Accepted submission (s): 57
problem Descriptionacboy was kidnapped!!  
He miss his mother very much and was very scare now. You can "t image how dark the" the "the" the "and" put into are, so poor:(.
as a smart Acmer, you want to get Acboy out of the monster ' s Labyrinth. If you arrive at the gate of the maze, the Monste say: "I had heard that is very clever, but if can ' t solve M Y problems, you'll die with Acboy. "
The problems of the monster is shown on the wall:
Each problem ' s first line is a integer N (the number of commands), and a word "FIFO" or "FILO". (You is very happy because you know "FIFO" stands for "first on first out", and "FILO" means "first on last Out").
and the following N lines, each of which is ' in M ' or ' out ', (M represent a integer).
and the answer of a problem are a passowrd of a door, so if you want to rescue acboy, answer the problem carefully!
 
Inputthe input contains multiple test cases.
The first line has one integer,represent the number oftest cases.
The input of each subproblem is described above.
Output
For each command "out", you should output a integer depend on the word was "FIFO" or "FILO", or a word "None" if you don ' t Has any integer.
Sample Input
Fifoin 1IN 2outout4 filoin 1IN 2outout5 fifoin 1IN 2outoutout5 filoin 1IN 2OUTIN 3OUT
Sample Output
122112none23
Source2007 Provincial Training Team Practice (1)
Recommendlcy


Topic Analysis:

Basic use of stacks and queues, simple questions.

In fact, the question is probably to let us write a stack and queue ourselves. However, as a long-known STL slag, there is no patience to write stack and queue again.

。 Hey, hey.


The code is as follows:

/* * A.cpp * Stack and queue simulation * *  Created on:2015 March 19 * author:administrator * *      #include <iostream> #include <cs tdio> #include <stack> #include <queue>using namespace Std;int main () {int t;scanf ("%d", &t); while (  t--) {int n;string type;cin >> n >> type;if (type = = "FIFO") {queue<int> q;string cmd;int num;int i;for (i = 0; I < n; ++i) {cin >> cmd;if (cmd = = "in") {cin >> num;q.push (num);} Else{if (q.empty () = = True) {printf ("none\n");} Else{int ans = q.front (), Q.pop ();p rintf ("%d\n", ans);}}} else{stack<int> st;string cmd;int  num;int i;for (i = 0; i < n; ++i) {cin >> cmd;if (cmd = = "in") {cin ;> Num;st.push (num);} Else{if (st.empty () = = True) {printf ("none\n");} Else{int ans = st.top (), St.pop ();p rintf ("%d\n", ans);}}}} return 0;}




(Hdu step 8.1.1) Acboy needs your help again! (Basic use of stacks and queues in STL)

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.