HDU 1702 acboy needs your help again!

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1702

Output the corresponding number according to the given requirements. "FIFO" refers to the concept of first-in-first-out, that is, the concept of queue. "Filo" refers to the first-out, that is, the form of stack ~ Define two functions, one queue and one stack!

 1 #include <iostream> 2 #include <cstdio> 3 #include <queue> 4 #include <stack> 5 #include <cstring> 6 using namespace std; 7  8 int s,p,o,z,q; 9 char ch[105],str[105];10 11 int FIFO(int w)12 {13     queue<int>q,qq;14     for (int i=0; i<w; i++)15     {16         scanf("%s",ch);17         if (strcmp(ch,"IN")==0)18         {19             scanf("%d",&o);20             q.push(o);21         }22         else if (strcmp(ch,"OUT")==0)23         {24             if (!q.empty())25             {26                 s=q.front();27                 cout<<s<<endl;28                 q.pop();29             }30             else31                 cout<<"None"<<endl;32 33         }34     }35 }36 int FILO(int w)37 {38     stack<int>q,qq;39     for (int i=0; i<w; i++)40     {41         scanf("%s",ch);42         if (strcmp(ch,"IN")==0)43         {44             scanf("%d",&p);45             q.push(p);46         }47         else if (strcmp(ch,"OUT")==0)48         {49             if (!q.empty())50             {51                 z=q.top();52                 cout<<z<<endl;53                 q.pop();54             }55             else56                 cout<<"None"<<endl;57         }58     }59 }60 int main ()61 {62     int n,m;63     while (cin>>n)64     {65         while (n--)66         {67             scanf ("%d%s",&m,str);68             //scanf("%s %d",ch,m);69             if (strcmp(str,"FIFO")==0)70                 FIFO(m);71             else72                 FILO(m);73         }74     }75     return 0;76 }

 

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.