Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e5f6295

Browse files
Initial commit
1 parent 905205c commit e5f6295

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//author @Nishant
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
6+
int main(){
7+
int t;
8+
cin >> t;
9+
while(t--){
10+
string s;
11+
cin >> s;
12+
if(s[0] == '>'){
13+
cout << 0 << endl;
14+
}else{
15+
int count = 0, ans = 0;
16+
for(int i = 0; i < s.size(); i++){
17+
if(s[i] == '<'){
18+
++count;
19+
}
20+
if(s[i] == '>'){
21+
--count;
22+
if(count == 0){
23+
ans = max(ans, i + 1);
24+
}
25+
if(count < 0){
26+
break;
27+
}
28+
}
29+
}
30+
cout << ans << endl;
31+
}
32+
}
33+
return 0;
34+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//author @Nishant
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
6+
int main(){
7+
int t;
8+
cin >> t;
9+
int br;
10+
int nested_depth=-1,open=0,first_pos=-1,count=0,matched_br=0,max_matched_br=-1,first_pos_matched_br =-1;
11+
while(t--){
12+
cin >> br;
13+
if(br == 1){
14+
open++;
15+
if(open > nested_depth){
16+
first_pos = count;
17+
nested_depth = open;
18+
}
19+
}else if(br == 2){
20+
open--;
21+
matched_br+=2;
22+
23+
if(matched_br>max_matched_br){
24+
max_matched_br = matched_br;
25+
first_pos_matched_br = count-max_matched_br+1;
26+
}
27+
if(open==0){
28+
matched_br=0;
29+
}
30+
}
31+
32+
}
33+
cout << nested_depth << " " << first_pos << " " << max_matched_br << " " << first_pos_matched_br << endl;
34+
return 0;
35+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /