1
1
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:
ParkMoonJ
2021-04-09 09:12:41 +08:00
parent 8eec06b3df
commit 54d5ef11e7
3 changed files with 76 additions and 0 deletions

8
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,8 @@
{
"files.associations": {
"iostream": "cpp",
"ostream": "cpp",
"*.rmd": "markdown",
"istream": "cpp"
}
}

BIN
3 栈和队列/3.19 Executable file

Binary file not shown.

68
3 栈和队列/3.19.cpp Normal file
View 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);
}