zoukankan      html  css  js  c++  java
  • STL应用——hdu1702(队列+堆栈)

    • 水题
    • 练习一下堆栈和队列的使用
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #include <vector>
    #include <list>
    #include <map>
    #include <stack>
    #include <queue>
    #include <map>
    using namespace std;
    
    int n;
    
    int main()
    {
    	scanf("%d",&n);
    	stack<int> a[10];
    	queue<int> b[10];
    	while(n--){
    		int m;
    		char str[10];
    		scanf("%d %s",&m,str);
    		char str1[10];
    		int m1;
    		if(str[2]=='F'){
    			queue<int> q;				//定义队列q 
    			while(m--){
    				scanf("%s",str1);
    				if(str1[0]=='I'){
    					scanf("%d",&m1);
    					q.push(m1);
    				}
    				else{
    					if(q.empty()){
    						printf("None
    ");
    					}
    					else{
    						printf("%d
    ",q.front());		//取队首元素 
    						q.pop();
    					}
    				}
    			}
    		} 
    		if(str[2]=='L'){
    			stack<int> s;					//定义堆栈s 
    			while(m--){
    				scanf("%s",str1);
    				if(str1[0]=='I'){
    					scanf("%d",&m1);
    					s.push(m1);
    				}
    				else{
    					if(s.empty()){
    						printf("None
    ");
    					}
    					else{
    						printf("%d
    ",s.top());			//取栈顶元素 
    						s.pop();
    					}
    				}
    			}
    		}
    	}
    	return 0;
    }
    
  • 相关阅读:
    get通配符
    常用正则表达式(合)
    2.A star
    1.序
    机器人运动规划04《规划算法》
    机器人运动规划03什么是运动规划
    6.2 性能优化
    6.1 内存机制及使用优化
    5.9 热修复技术
    5.8 反射机制
  • 原文地址:https://www.cnblogs.com/xzxl/p/7329707.html
Copyright © 2011-2022 走看看