fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, q, count;
  6. char ungulate;
  7. bool b;
  8. cin >> n;
  9.  
  10. for ( int i = 0; i < n; i++ ) {
  11. int count = 0;
  12. b = true;
  13. cin >> q;
  14.  
  15. for ( int j = 0; j < q; j++ ) {
  16. cin >> ungulate;
  17. if ( ungulate == '>' ) {
  18. count++;
  19. }
  20. else {
  21. count--;
  22. }
  23. if ( count < 0 ){
  24. b = false;
  25. }
  26. }
  27.  
  28. if ( count != 0 ) {
  29. b = false;
  30. }
  31.  
  32. if ( b ) {
  33. cout << "legal" << endl;
  34. }
  35. else {
  36. cout << "illegal" << endl;
  37. }
  38. }
  39. return 0;
  40. }
Success #stdin #stdout 0s 4516KB
stdin
5
4 ><><
10 >>><<>><<<
8 >><<<>><
3 >><
12 ><>><>>><<<<
stdout
legal
legal
illegal
illegal
legal