问题描述
我正在努力处理此代码。程序意外终止。请帮忙 问题链接:https://www.hackerrank.com/challenges/maximum-element/problem
10
1 97
2
1 20
2
1 26
1 20
2
3
1 91
如果我们在程序中输入上述数字...没有到最后但在中途停止执行 请帮助我找到问题...动态分配或任何功能是否有问题...如果您有时间,请访问问题链接并寻求帮助。.谢谢
class stack
{
public:
int top = -1;
int *s;
};
void create(stack *st,int n)
{
st->s = new int[n];
}
void del(stack *st)
{
st->top--;
}
void push(stack *st,int x)
{
st->top++;
st->s[st->top] = x;
}
int main()
{
long int t;
stack st;
int choice;
int number;
int max =-1;
cin>>t;
create(&st,t);
while(t--)
{
cin>>choice;
if(choice == 1)
{
cin>>number;
push(&st,number);
if(max < number)
max = number;
}
else if(choice == 2)
{
del(&st);
}
else
{
return max;
}
}
return 0;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)