fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. class Solution {
  7. private:
  8.  
  9. public:
  10.  
  11. };
  12.  
  13. int main()
  14. {
  15. ios_base::sync_with_stdio(false);
  16. //cin.tie(NULL);
  17. int t,ans;
  18. string s;
  19. vector<char> v;
  20. cin >> t;
  21. while (t--) {
  22. cin >> s;
  23. ans = 0;
  24. for (int i=0;i<s.size();i++) {
  25. if (s[i]=='<') {
  26. v.push_back('<');
  27. }
  28. else {
  29. if (v.empty()) {
  30. break;
  31. }
  32. else {
  33. v.pop_back();
  34. }
  35. if (v.empty()) {
  36. ans = i+1;
  37. }
  38. }
  39. }
  40. cout << ans << endl;
  41. }
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 4452KB
stdin
7
<<>>
><
<>
<><><>
<>><><><>
<<<>>><><>
><><>
stdout
4
0
2
6
2
10
0