HDU 1702 acboy needs your help again!

Source: Internet
Author: User

Problem descriptionacboy was kidnapped !!
He miss his mother very much and is very scare now. You can't image how dark the room he was put into is, so poor :(.
As a smart acmer, you want to get acboy out of the monster's Labyrinth. but when you arrive at the gate of the maze, the monste say: "I have heard that you are very clever, but if you can't solve my problems, you will 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 are very happy because you know "FIFO" stands for "first in first out", and "Filo" means "first in last out ").
And the following n lines, each line is "in M" or "out", (M represent a integer ).
And the answer of a problem is 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.
And the input of each subproblem are described above.
Outputfor each command "out", you should output a integer depend on the word is "FIFO" or "Filo", or a word "NONE" if you don't have any integer.
Sample Input
44 bytes oin 1In 2outout4 filoin 1In 2outout5 bytes oin 1In 2outoutout5 filoin 1In 2 outin 3out

Sample output
 
122379none23
STL, =. =, used in queue and stack.
# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <limits. h >#include <queue >#include <stack> using namespace STD; char C [10]; int X; void solve_s (int n) {stack <int> S; while (n --) {scanf ("% s", c); If (! Strcmp (C, "in") {scanf ("% d", & X); S. Push (x) ;}else {If (! S. empty () {printf ("% d \ n", S. top (); S. pop ();} else printf ("None \ n") ;}} void solve_q (int n) {queue <int> q; while (n --) {scanf ("% s", c); If (! Strcmp (C, "in") {scanf ("% d", & X); q. Push (x) ;}else {If (! Q. empty () {printf ("% d \ n", Q. front (); q. pop () ;}else printf ("None \ n") ;}} int main () {int t, n; char STR [10]; scanf ("% d", & T); While (t --) {scanf ("% d % s", & N, STR); If (! Strcmp (STR, "FIFO") solve_q (n); else solve_s (n);} return 0 ;}


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.