[2016-01-19][HDU][1702]

[2016-01-19][HDU][1702]

  • 时间:2016-01-19  13:26:37  星期二
  • 题目编号:HDU 1702
  • 题目大意:给定 FIFO 和 FILO模式,输出结果
  • 方法:用stack和queue模拟一遍过程即可.  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        string str;
        cin>>n>>str;
        if(str == "FIFO")
        {
            int tmp;
            queue<int> qu;
            for(int i = 0;i < n ;i++)
            {
                cin>>str;
                if(str == "IN"){
                    cin>>tmp;
                    qu.push(tmp);
                }else {
                    if(qu.empty() ){
                        puts("None");
                    }
                    else {
                        printf("%d\n",qu.front());
                        qu.pop();
                    }
                }
            }
        }else if (str == "FILO")
        {
            int tmp;
            stack<int> stk;
            for(int i = 0;i < n ;i++)
            {
                cin>>str;
                if(str == "IN"){
                    cin>>tmp;
                    stk.push(tmp);
                }else {
                    if(stk.empty() ){
                        puts("None");
                    }
                    else {
                        printf("%d\n",stk.top());
                        stk.pop();
                    }
                }
            }
        }  
    }
    return 0;
}


来自为知笔记(Wiz)


posted on 2016-01-19 17:35  红洋  阅读(123)  评论(0)    收藏  举报

导航