SDUT 2088 refresh的停车场
2016-07-20 18:20
453 查看
点击打开题目链接
#include <bits/stdc++.h> using namespace std; string _stack[200100], _queue[200100]; int main() { int n, m; string str, num; while(cin >> n >> m) { int flag = 1, top = 0, _front = 0, _rear = 0; for(int i = 1; i <= m; i++) { cin >> str; if(str == "Add") { cin >> num; if(top < n) { _stack[++top] = num; } else { _queue[++_rear] = num; } } else if(str == "Del") { if(top <= 0) { flag = 0; } else if(_front <= _rear) { _stack[top] = _queue[++_front]; } else if(_front > _rear) { top --; } } else if(str == "Out") { if(_front <= _rear) { _front++; } else { flag = 0; } } } if(flag == 0) { cout << "Error" << endl; } else { while(top) { cout << _stack[top--] << endl; } } } return 0; } 2: #include <bits/stdc++.h> using namespace std; int main() { int n, m; int flag; char str[10]; string str1; while(cin >> n >> m) { queue<string>Q; stack<string>S; flag = 1; while(m --) { scanf("%s", str); if(strcmp(str, "Add") == 0) { cin >> str1; if(S.size() == n) { Q.push(str1); } else { S.push(str1); } } else if(strcmp(str, "Del") == 0) { if(S.empty()) { flag = 0; } else { S.pop(); if(!Q.empty()) { S.push(Q.front()); Q.pop(); } } } else if(strcmp(str, "Out") == 0) { if (!Q.empty()) { Q.pop(); } else { flag = 0; } } } if(flag == 0) { cout << "Error" << endl; } else while(!S.empty()) { cout << S.top() << endl; S.pop(); } } return 0; }
相关文章推荐
- C#线程队列用法实例分析
- 算法系列15天速成 第九天 队列
- C++基于栈实现铁轨问题
- C语言单链队列的表示与实现实例详解
- 浅析C语言中堆和栈的区别
- C语言栈的表示与实现实例详解
- C语言实现颠倒栈的方法
- 算法系列15天速成 第十天 栈
- mysql 队列 实现并发读
- C#队列Queue用法实例分析
- C#多线程处理多个队列数据的方法
- C语言循环队列的表示与实现实例详解
- C++循环队列实现模型
- C#内置队列类Queue用法实例
- 一看就懂:图解C#中的值类型、引用类型、栈、堆、ref、out
- Array栈方法和队列方法的特点说明
- C#通过链表实现队列的方法
- java数据结构之java实现栈
- C#队列Queue多线程用法实例
- JAVA 虚拟机 栈