mirror of
https://github.com/ParkMoonJ/KaoYan.git
synced 2026-06-18 01:36:31 +08:00
Update 3.19
This commit is contained in:
8
.vscode/settings.json
vendored
Normal file
8
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"iostream": "cpp",
|
||||
"ostream": "cpp",
|
||||
"*.rmd": "markdown",
|
||||
"istream": "cpp"
|
||||
}
|
||||
}
|
||||
BIN
3 栈和队列/3.19
Executable file
BIN
3 栈和队列/3.19
Executable file
Binary file not shown.
68
3 栈和队列/3.19.cpp
Normal file
68
3 栈和队列/3.19.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
#define MAXSIZE 100
|
||||
|
||||
struct Stack{
|
||||
char data[MAXSIZE];
|
||||
int top;
|
||||
} S;
|
||||
|
||||
char a[MAXSIZE];
|
||||
|
||||
void InitStack(Stack &S) {
|
||||
char data[MAXSIZE] = {};
|
||||
int top = -1;
|
||||
}
|
||||
|
||||
bool Push(Stack &S, char x) {
|
||||
if (S.top == MAXSIZE - 1) {
|
||||
return false;
|
||||
} else {
|
||||
++S.top;
|
||||
S.data[S.top] = x;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Pop(Stack &S, char x) {
|
||||
if (S.top == -1) {
|
||||
return false;
|
||||
} else {
|
||||
x = S.data[S.top];
|
||||
--S.top;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Bracket(char *a) {
|
||||
char x;
|
||||
|
||||
InitStack(S);
|
||||
for (int i = 0; a[i]; i++) {
|
||||
if (a[i] == '(' || a[i] == '[' || a[i] == '{') {
|
||||
Push(S, a[i]);
|
||||
} else if (a[i] == ']') {
|
||||
Pop(S, x);
|
||||
if (x != '[') {
|
||||
return false;
|
||||
}
|
||||
} else if (a[i] == ')') {
|
||||
Pop(S, x);
|
||||
if (x != '(') {
|
||||
return false;
|
||||
}
|
||||
} else if (a[i] == '}') {
|
||||
Pop(S, x);
|
||||
if (x != '{') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
cin.getline(a, MAXSIZE);
|
||||
return Bracket(a);
|
||||
}
|
||||
Reference in New Issue
Block a user