-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path26.cpp
More file actions
42 lines (31 loc) · 758 Bytes
/
26.cpp
File metadata and controls
42 lines (31 loc) · 758 Bytes
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
// O(n * length(s))
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <iomanip>
using namespace std;
#define FILE_IO {freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);}
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL)
inline int solve(string &s) {
int res = 0;
for (int sm = 0, l = 0, i = 0; i < s.size(); ++i) {
sm += s[i] == '<';
sm -= s[i] == '>';
if (sm == 0) res = i + 1;
else if (sm < 0) break;
}
return res;
}
int main() {
FAST_IO;
// FILE_IO;
int n; cin >> n;
string s;
for (int i = 0; i < n; ++i) {
cin >> s;
cout << solve(s) << endl;
}
return 0;
}