fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long int
  3. using namespace std;
  4. void test()
  5. {
  6. int t;
  7. cin>>t;
  8. while(t--)
  9. {
  10. int count=0,count1=0,cnt=0;
  11. string s;
  12. cin>>s;
  13. stack<char>st;
  14. for(int i=0;i<s.size();i++)
  15. {
  16. if(s[i]=='<')
  17. {
  18. st.push(s[i]);
  19. }
  20. else
  21. {
  22. if(st.empty())
  23. {
  24. break;
  25. }
  26. else
  27. {
  28. st.pop();
  29. count+=2;
  30. }
  31. }
  32. }
  33. cout<<count<<endl;
  34. }
  35. }
  36. int main()
  37. {
  38. ios_base::sync_with_stdio(0);
  39. cin.tie(0); cout.tie(0);
  40. test();
  41. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Standard output is empty