fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(void) {
  5. int t;
  6. scanf("%d", &t);
  7. for(; t > 0; t--){
  8. char *str;
  9. scanf("%s", str);
  10. int l = (int)strlen(str);
  11. if(l >= 1){
  12. char stack[l];
  13. int top = -1, prLen = 0; //prLen - prefix length
  14. //string is valid only when str[0] == '<', stacked must be pushed atleast once in start
  15. // and no('<') <= no('>')
  16. if(str[0] == '<'){
  17. for(int i = 0; i < l; i++){
  18. if(str[i] == '<'){
  19. stack[++top] = str[i];
  20. prLen++;
  21. }
  22. else if(str[i] == '>' && top != -1){
  23. top--;
  24. prLen++;
  25. }
  26. if(top == -1)
  27. break;
  28. }
  29. if(top == -1)
  30. printf("%d\n", prLen);
  31. else
  32. printf("%d\n", 0);
  33. }
  34. else
  35. printf("%d\n", 0);
  36.  
  37. }
  38.  
  39.  
  40. }
  41. return 0;
  42. }
  43.  
  44.  
Runtime error #stdin #stdout 0s 4508KB
stdin
1
<<>>
stdout
Standard output is empty