This repository was archived by the owner on May 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatchbracketsnew.cpp
More file actions
80 lines (77 loc) · 1.48 KB
/
matchbracketsnew.cpp
File metadata and controls
80 lines (77 loc) · 1.48 KB
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
#include<iostream>
#include<vector>
#include<stack>
#include<algorithm>
using namespace std;
int main(){
int n, count = 0, acount=0;
cin >> n;
stack<char> a;
vector<int> seq, vcount1, vcount2, tempcount, alter;
tempcount.push_back(0);
for(int i = 0; i<n; i++){
int x;
char y;
cin >> x;
if(x==1){
y = '(';
}
if(x==2){
y = ')';
}
if(x==3){
y = '[';
}
if(x==4){
y = ']';
}
a.push(y);
seq.push_back(x);
char top;
while(a.empty()==false && a.top()==']' || a.empty()==false && a.top()==')'){
top = a.top();
a.pop();
a.pop();
count++;
if(top==')'){
vcount1.push_back(count*2);
}
if(top = ']'){
vcount2.push_back(count*2);
}
}
if(a.empty()){
tempcount.push_back(count*2);
count = 0;
}
}
for(int i=1; i<tempcount.size(); i++){
for(int j=0; j<tempcount[i]+tempcount[i-1]; j++){
if(seq[j]==1){
acount++;
j++;
if(seq[j]==3){
acount++;
continue;
}
}
}
alter.push_back(acount);
acount = 0;
}
for(int i=1; i<tempcount.size(); i++){
for(int j=0; j<tempcount[i]+tempcount[i-1]; j++){
if(seq[j]==1){
acount++;
j++;
if(seq[j]==3){
acount++;
continue;
}
}
}
alter.push_back(acount);
acount = 0;
}
cout << *max_element(alter.begin(), alter.end()) << " " << *max_element(vcount1.begin(), vcount1.end()) << " " << *max_element(vcount2.begin(), vcount2.end());
}