您的位置:首页 > 其它

28-题目1108:堆栈的使用

2016-03-03 19:43 393 查看

http://ac.jobdu.com/problem.php?pid=1108

题目比较简单
#include<stdio.h>
#include<string.h>
#include<fstream>
#include<iostream>
using namespace std;

int main(){
int n;
ifstream cin("data.txt");
while (cin >> n && n !=0 )
{
int i, tail = -1;
char operation;
int *stack = new int
;
for (i = 0; i < n; i++)
{
cin >> operation;
if (operation == 'P')
cin >> stack[++tail];
else if (operation == 'O')
{
if (tail == -1)
tail = -1;
else
tail--;
}
else if (operation == 'A')  //查询
{
if (tail >= 0)
cout << stack[tail] << endl;
else
cout << "E" << endl;
}
}
cout << endl;
}
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: