1 Star 0 Fork 0

OuroborosInc / OuroborosOJ-2021b

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
6.2 E 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
vulcan626 提交于 2022-06-16 09:18 . Data-Structure-main
//设栈S的初始状态为空,元素a,b,c,d,e,f,g依次入栈,出栈顺序为b,d,c,f,e,a,g那么栈容量至少应该是3。如果任意给你一个出栈序列,你能编程判断相应的栈容量至少是多少吗?
//元素a,b,c,d,e,f,g依次入栈情况下的一种出栈序列。
//对应出栈序列的栈容量至少是多少。
//b d c f e a g
//3
#include<iostream>
#include<stack>
using namespace std;
int maxstack=0;
void ismax(int t)
{
if(t>maxstack)
maxstack=t;
}
int main()
{
stack<char>s;
int temp=0;
char ch0='a',ch1[8];
for (int i=0;i<7;i++)
cin>>ch1[i];
int i=0,flag=1;
while(i<7)
{
if(ch0==ch1[i])
{
s.push(ch0);
temp++;
ismax(temp);
s.pop();
temp--;
ch0++;
i++;
}
else if(!s.empty()&&s.top()==ch1[i])
{
s.pop();
temp--;
i++;
}
else if(ch0<='g')
{
s.push(ch0);
temp++;
ismax(temp);
ch0++;
}
else
{
flag=0;
break;
}
}
cout<<maxstack<<endl;
return 0;
}
C++
1
https://gitee.com/ouroborosinc/OuroborosOJ-2021b.git
git@gitee.com:ouroborosinc/OuroborosOJ-2021b.git
ouroborosinc
OuroborosOJ-2021b
OuroborosOJ-2021b
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891