题解
2023-03-31 21:35:39
发布于:上海
151阅读
0回复
0点赞
#include <iostream>
#include <string.h>
using namespace std;
int main() {
int n;
char op[8];
int data[100000] = {0};
int size = 0, temp;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> op;
if (strcmp(op, "push") == 0)
{
cin >> temp;
data[size] = temp;
size++;
}
else
{
if (strcmp(op, "pop") == 0)
{
if (size > 0)
{
data[size - 1] = 0;
size -= 1;
}
else
{
cout << "error" << endl;
}
}
else if (strcmp(op, "top") == 0)
{
if (size > 0)
{
cout << data[size - 1] << endl;
}
else
{
cout << "error" << endl;
}
}
else if (strcmp(op, "get_min") == 0)
{
if (size > 0)
{
temp = data[0];
for (int j = 1; j < size; j++)
{
if (data[j] < temp)
temp = data[j];
}
cout << temp << endl;
}
else
{
cout << "error" << endl;
}
}
else
{
cout << "error" << endl;
}
}
}
return 0;
}
这里空空如也
有帮助,赞一个