fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long int
  3. using namespace std;
  4.  
  5. bool iscomp(char a,char b)
  6. {
  7. if(a=='<' && b=='>')
  8. return true;
  9.  
  10. else
  11. false;
  12. }
  13.  
  14. int main()
  15. {
  16. ll t;
  17. cin>>t;
  18. while(t--)
  19. {
  20. string s;
  21. cin>>s;
  22. stack<char> a;
  23. ll count=0;
  24. ll max=INT_MIN;
  25. for(ll i=0;i<s.size();i++)
  26. {
  27. if(s[i]=='<')
  28. {
  29. a.push(s[i]);
  30. }
  31.  
  32.  
  33. else
  34. {
  35. if(!a.empty())
  36. {
  37. a.pop();
  38. count+=2;
  39. }
  40.  
  41. }
  42. if(a.empty() && count>max)
  43. max=count;
  44. }
  45. cout<<max<<endl;
  46. }
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0s 15240KB
stdin
1
<<><><><><<>>>>
stdout
14