栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

2021.12.1学习总结

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

2021.12.1学习总结

今天早上满课,下午和晚上就刷了vj上的3道栈题主要是边刷边学习,过了一个两个没过。一直在找bug,就是过不了。
过了那个题的题解跟代码。https://vjudge.net/contest/471327#problem/D
思路:两个数组,一个是自然数1到N,一个是你输入的序列,从1开始入栈,接着和输入的序列开始比较,不相同,自然数后移接着下一个入栈,相同就出栈,序列后移,后移之后在和栈里的栈顶相比较,相同就出栈,不相同自然数后移入栈,所有数据执行完后,当栈顶为空则为合法序列,否则不合法。
AC代码:
#include
#include
#define STACKSIZE 110
int push(int mystack[],int x,int top);
int stacktop(int mystack[],int top);
int pop(int mystack[],int top);
int empty(int top);
void hf(int instack[],int outstack[],int n)
{
int mystack[STACKSIZE];
int i,j=0,top=-1;
for(i=0;i {
top=push(mystack,instack[i],top);
while(empty(top)&&stacktop(mystack,top)outstack[j])
{
j++;
top=pop(mystack,top);
}
}
if(top
-1) printf(“Yesn”);
else printf(“Non”);
}
int push(int mystack[],int x,int top)
{

mystack[++top]=x;
return top;

}
int stacktop(int mystack[],int top)
{
return mystack[top];
}
int pop(int mystack[],int top)
{
mystack[top–];
return top;
}
int empty(int top)
{
return top==-1?0:1;
}
int main()
{
int N,i;
int instack[STACKSIZE];
int outstack[STACKSIZE];
while(scanf("%d",&N)&&N!=0)
{

 	memset(instack,0,sizeof instack);
 	memset(outstack,0,sizeof outstack);
 	for(i=0;i 

}
今天学的很少,找错找了很久一直过不了,那两个没过的代码就不写了,明天过了在写,明天接着学习,加油!睡觉,晚安。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/629319.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号