fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. #include<stack>
  4. #include<string.h>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.  
  10. long long T,i,counting;
  11.  
  12. cin>>T;
  13.  
  14. while(T--)
  15. {
  16.  
  17. stack<char> s;
  18. string arrow;
  19.  
  20. cin>>arrow;
  21.  
  22.  
  23. counting=0;
  24.  
  25. if(arrow[0] != '<')
  26. {
  27. cout<<0<<"\n";
  28. }
  29.  
  30. else
  31. {
  32. for(i=0;i<arrow.size();i++)
  33. {
  34.  
  35. if(arrow[i]=='<')
  36. {
  37. s.push(arrow[i]);
  38. }
  39. else if(arrow[i]=='>')
  40. {
  41. if(!s.empty())
  42. {
  43. if(s.top()=='<')
  44. {
  45. s.pop();
  46. counting+=2;
  47. }
  48. }
  49.  
  50.  
  51.  
  52. }
  53.  
  54. }
  55. if(s.empty())
  56. {
  57. cout<<counting<<"\n";
  58. }
  59. else
  60. {
  61. cout<<0<<"\n";
  62. }
  63. }
  64. }
  65. }
  66.  
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
Standard output is empty