98-7
来源:互联网 发布:个人考勤软件 编辑:程序博客网 时间:2024/06/04 17:49
({[入栈 )}]于栈顶比较
<span style="font-size:14px;">#include <iostream>#include <stdlib.h>#include <stdbool.h>using namespace std;typedef struct node{ char c; struct node* pnext;}qnode,*pnode;typedef struct stack{ pnode top; pnode botton;}qstack,*pstack;bool empty(pstack s){ if(s->top==s->botton) return true; else return false;}void init(pstack s){ s->top=(pnode)malloc(sizeof(node)); s->botton=s->top; s->botton->pnext=NULL;}void push(pstack s,char c_){ pnode q; q=(pnode)malloc(sizeof(qnode)); q->c=c_; q->pnext=s->top; s->top=q;}void pop(pstack s){ char e; pnode temp; if(empty(s)) cout<<"erro"; else { e=s->top->c; temp=s->top; s->top=temp->pnext; free(temp); }}char gettop(pstack s){ char e; e=s->top->c; return e;}int length(pstack s){ int i=0; pnode q; q=s->top; while(q!=s->botton) { i++; q=q->pnext; } return i;}int judge(pstack s,char a[],int i){ int j=0; char k; for(j=0;j<i;j++) { k=a[j]; if(a[j]=='(' || a[j]=='{' || a[j]=='[') { push(s,a[j]); } else if(a[j]==')') { k=gettop(s); if(k=='(') pop(s); else return -1; } else if(a[j]==']') { k=gettop(s); if(k=='[') pop(s); else return -1; } else if(a[j]=='}') { k=gettop(s); if(k=='{') pop(s); else return -1; } } return length(s);}int main(){ int p; qstack s; char a[100]; char ch; int i=0; while( ( ch = getchar() ) != '\n' ) { a[i]=ch; i++; } init(&s); p=judge(&s,a,i); if(p==0) cout<<"yes"; if(p>0) cout<<") ] }"; if(p<0) cout<<"( [ {";}</span>
0 0
- 98-7
- 98
- 98
- TextBox 中英文输入方法切换 98-7-22
- 100+99+98-97-96-95+ ...+10+9+8-7-6-5项数组数
- 58Q游戏(4)73(5)85(6)98(7)
- 7-98 不能用循环是一件多么悲伤的事(30 分)
- Windows 98
- nyoj-98
- France '98
- 98 拖拽
- ocp-98
- eerThcraeSyraniBetadilaV.98
- 题目98
- 98-12
- 8+98+
- NYOJ 98
- 练习98
- oleDBConn.ServerVersion 未注册"Microsoft.ACE.OLEDB.12.0"提供程序 或oleDBConn(0x80004005)或oleDBConn 未知错误
- 【方法】方法重载与方法重写
- 什么是Hive
- leetcode :Binary Search:Two Sum II - Input array is sorted(069)
- 《集体智慧编程》笔记2.1---第二章
- 98-7
- 使用LinearLayout+TextView实现底部导航栏,重复切换页面不会重新加载
- 【BZOJ】3016: [Usaco2012 Nov]Clumsy Cows
- Java transient关键字使用小记
- leetcode :Binary Search:Dungeon Game(174)
- 《数学之美》读书笔记3
- 大话直播,做直播看我就够了
- mycat 垂直切分和水平切分配置示例
- 移动端判断是否处于横屏还是竖屏状态