fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define all(c) c.begin(), c.end()
  4. #define tr(container, it) \
  5.   for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. // ios_base::sync_with_stdio(false);
  12. // cin.tie(NULL);
  13. int t,i;
  14. cin>>t;
  15. for(int j=0;j<t;j++) {
  16. string str;
  17. stack<char> stk;
  18. cin>>str;
  19. bool fail = false;
  20. int count = 0;
  21. int max_count = 0;
  22. for(i=0;i<str.length();i++) {
  23. if(str.at(i) == '>' && stk.empty() == true) {
  24. fail = true;
  25. count = 0;
  26. if(count >= max_count){
  27. max_count = count;
  28. }
  29. }
  30. else {
  31. if(str.at(i) == '<'){
  32. stk.push('<');
  33. // count++;
  34. if(count >= max_count){
  35. max_count = count;
  36. }
  37. }
  38. else if(str.at(i) == '>'){
  39. stk.pop();
  40. count+=2;
  41. if(count >= max_count){
  42. max_count = count;
  43. }
  44. }
  45. }
  46. }
  47. if(stk.empty() == false) {
  48. count = 0;
  49. if(count >= max_count){
  50. max_count = count;
  51. }
  52. }
  53. if(max_count!=1)
  54. cout<< max_count<<endl;
  55. else
  56. cout<<0<<endl;
  57. }
  58. return 0;
  59. }
  60.  
Success #stdin #stdout 0s 4340KB
stdin
Standard input is empty
stdout
Standard output is empty