diff --git a/.vscode/settings.json b/.vscode/settings.json index 04c58c2..e31da83 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,10 @@ "iostream": "cpp", "ostream": "cpp", "*.rmd": "markdown", - "istream": "cpp" + "istream": "cpp", + "__locale": "cpp", + "__string": "cpp", + "string": "cpp", + "string_view": "cpp" } } \ No newline at end of file diff --git a/3 栈和队列/3 栈和队列.md b/3 栈和队列/3 栈和队列.md index 09e5094..8fb62a1 100644 --- a/3 栈和队列/3 栈和队列.md +++ b/3 栈和队列/3 栈和队列.md @@ -376,6 +376,7 @@ bool bracket(char a) { } } } + return true; } ``` diff --git a/3 栈和队列/3.19 b/3 栈和队列/3.19 index 38ad345..897c3d9 100755 Binary files a/3 栈和队列/3.19 and b/3 栈和队列/3.19 differ diff --git a/3 栈和队列/3.19.cpp b/3 栈和队列/3.19.cpp index f2243d2..620262b 100644 --- a/3 栈和队列/3.19.cpp +++ b/3 栈和队列/3.19.cpp @@ -1,5 +1,6 @@ #include #include +#include using namespace std; #define MAXSIZE 100 @@ -35,34 +36,39 @@ bool Pop(Stack &S, char x) { return true; } -bool Bracket(char *a) { +bool Bracket(char *a, int i) { 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] == ']') { + for (int j = 0; j == i; j++) + { + if (a[j] == '(' || a[j] == '[' || a[j] == '{') { + Push(S, a[j]); + } else if (a[j] == ']') { Pop(S, x); if (x != '[') { return false; } - } else if (a[i] == ')') { + } else if (a[j] == ')') { Pop(S, x); if (x != '(') { return false; } - } else if (a[i] == '}') { + } else if (a[j] == '}') { Pop(S, x); if (x != '{') { return false; } } } + return true; } int main() { - int n; - cin.getline(a, MAXSIZE); - return Bracket(a); + int i = 0; + while ((a[i] = cin.get()) != '\n') { + ++i; + } + cout << Bracket(a, i - 1); + return 0; } \ No newline at end of file