fork download
  1. // 2018-02-19 00:37:42
  2. #include <iostream>
  3. #include <stack>
  4.  
  5. using namespace std;
  6. int main(){
  7. int t,count;
  8. cin>>t;
  9. string input;
  10. while(t--) {
  11. cin>>input;
  12. stack<char> exp;
  13. // cout<<"size of stack = "<<exp.size()<<endl;
  14. count = 0;
  15. // cout<<"after count"<<endl;
  16. for (int i = 0; i < input.size(); i++) {
  17. if( input[i] == '<') {
  18. exp.push(input[i]);
  19. } else if (input[i] == '>') {
  20. if(exp.size() > 0 && exp.top() == '<' ) {
  21. exp.pop();
  22. count += 2;
  23. }
  24. } else
  25. break;
  26. }
  27. if(exp.empty())
  28. cout<<count<<endl;
  29. else
  30. cout<<"0"<<endl;
  31. // while(exp.empty()) exp.pop();
  32. // cout<<count<<endl;
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0s 4308KB
stdin
7
<<>>
<<<>>>
><<<<<
<>>>>>
<<<>>>>>
<><><>
<><<>>
stdout
4
6
0
2
6
6
6