fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. long long t=0,m=0,n=0;
  7. char x[1000001];
  8. cin >> t;
  9.  
  10. while(t--)
  11. {
  12. cin >> x;
  13. //find n;
  14. int j;
  15. for(j = 0; x[j]!='\0'; j++);
  16. n = j;
  17.  
  18. for(m = n; m > 0 ; m--)
  19. {
  20. long long sum = 0;
  21. for(int i = 0; i < m; i++)
  22. {
  23. if(x[i]=='<')sum++;
  24. else if(x[i]=='>') sum--;
  25. //cout << x[i] << " " << sum << " ";
  26.  
  27. if(sum < 0) m--;
  28. }
  29.  
  30. if(sum == 0) {cout << m << endl; m = -10;}
  31. }
  32.  
  33. if(m != -11) cout << 0 << endl;
  34. }
  35.  
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 4192KB
stdin
1
<<><>>
stdout
6