-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcorrect-bracket-sequence.cpp
51 lines (45 loc) · 1.01 KB
/
correct-bracket-sequence.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
// This code was created with the support of Sergo.
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <queue>
typedef long long ll;
typedef double ld;
typedef unsigned long long ull;
using namespace std;
void file() {
freopen("brackets.in","r", stdin);
freopen("brackets.out","w", stdout);
}
// void ...
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
file();
string s;
while(cin >> s) {
char ans[10000 + 1];
int j = 0, sz = 0;
for(int i = 0; i < s.size(); i++) {
if(sz != 0 && j > 0 && (s[i] == ')' && ans[j - 1] == '(') || (s[i] == ']' && ans[j - 1] == '[')) {
j--;
sz--;
}
else {
ans[j] = s[i];
j++;
sz++;
}
}
if(sz == 0) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
}
}