Skip to content

Commit 2cee2c8

Browse files
committed
Solve problem Compilers and parsers from CodeChef
1 parent d5f0e21 commit 2cee2c8

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

Diff for: CodeChef/Compilers and parsers.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
using namespace std;
5+
6+
int main() {
7+
int t;
8+
cin >> t;
9+
10+
string s;
11+
int ans, opens;
12+
while(t--) {
13+
cin >> s;
14+
15+
ans = opens = 0;
16+
17+
for(int i = 0; i < s.length(); i++)
18+
if(s[i] == '<')
19+
opens++;
20+
else {
21+
opens--;
22+
23+
if(opens == 0) ans = i + 1;
24+
if(opens < 0) break;
25+
}
26+
27+
cout << ans << endl;
28+
}
29+
30+
return 0;
31+
}

Diff for: CodeChef/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Problems links
2+
3+
- [Compilers and parsers](https://www.codechef.com/problems/COMPILER)

0 commit comments

Comments
 (0)