fork download
  1. #include<iostream>
  2. #include<cstring>
  3. using namespace std;
  4. int main()
  5. {
  6. int t;
  7. cin >> t;
  8. while (t--)
  9. {
  10. string s;
  11. cin >> s;
  12. int n=s.size();
  13.  
  14. int count1 = 0;int flag=0;
  15. for (int i = 0;i <n;i++)
  16. {
  17.  
  18.  
  19.  
  20. if (s[i] == '<')
  21. count1++;
  22. if (s[i] == '>')
  23. count1--;
  24. if(count1==0)
  25. flag=i;
  26. if(count1<0)
  27. {
  28. cout<<i<<endl;
  29. break;
  30. }
  31. if(i==n-1)
  32. {
  33.  
  34. if(count1!=0)
  35. {
  36. if(flag==0)
  37. {
  38. cout<<0<<endl;
  39. break;
  40. }
  41. cout<<flag+1<<endl;
  42.  
  43. break;
  44. }
  45.  
  46. cout<<n<<endl;
  47. break;
  48. }
  49.  
  50.  
  51.  
  52.  
  53.  
  54. }
  55. }
  56. return 0;
  57. }
  58.  
Success #stdin #stdout 0s 4396KB
stdin
5
<><
<<>
<<<>>>
><
<><><><<>>
stdout
2
0
6
0
10