-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path3-3-1.cpp
88 lines (88 loc) · 1.36 KB
/
3-3-1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include<iostream>
using namespace std;
#define MAXSIZE 10
#define ELEMTYPE char
typedef struct{
ELEMTYPE data[MAXSIZE];
int top; //top 指针
}SqStack;
void InitStack(SqStack &stk){
stk.top=0;
}
bool StackEmpty(SqStack stk){
if(!stk.top)return true;
return false;
}
//注意:一定要加引用型!
bool push(SqStack &stk,ELEMTYPE x){
//MAXIZE
if(stk.top<MAXSIZE){
stk.data[stk.top++]=x;
return true;
}
return false;
}
bool pop(SqStack &stk,ELEMTYPE &x){
if(stk.top>0){
x=stk.data[--stk.top];
return true;
}
return false;
}
bool gettop(SqStack stk,ELEMTYPE &x){
if(stk.top){
x=stk.data[stk.top-1];
return true;
}
return false;
}
int main(){
SqStack s;
InitStack(s);
char x,tmp;
cin>>x;
while(x!='q'){
switch(x){
case '{':
push(s,x);
break;
case '}':
if(!pop(s,tmp))return 1;
if(tmp!='{'){
cout<<"error:}"<<endl;
return 1;
}
break;
case '(':
push(s,x);
break;
case ')':
if(!pop(s,tmp))return 1;
if(tmp!='('){
cout<<"error:)"<<endl;
return 1;
}
break;
case '[':
push(s,x);
break;
case ']':
if(!pop(s,tmp))return 1;
if(tmp!='['){
cout<<"error:]"<<endl;
return 1;
}
break;
default:
cout<<"error:char"<<endl;
return 1;
}
cin>>x;
}
if(StackEmpty){
cout<<"error:last"<<endl;
return 1;
}
cout<<"true"<<endl;
return 0;
}