nikolayneykov

Untitled

Feb 10th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. using System;
  2.  
  3. class BalancedBrackets
  4. {
  5. static void Main(string[] args)
  6. {
  7. int n = int.Parse(Console.ReadLine());
  8. int opening = 0;
  9. int closing = 0;
  10. for (int i = 0; closing <= opening && i < n; i++)
  11. {
  12. string line = Console.ReadLine();
  13. if (line == "(")
  14. {
  15. opening++;
  16. }
  17. else if (line == ")")
  18. {
  19. closing++;
  20. }
  21. }
  22. Console.WriteLine(opening == closing ? "BALANCED" : "UNBALANCED");
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment