Advertisement
Guest User

Untitled

a guest
Sep 4th, 2021
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9.  
  10. int n = int.Parse(Console.ReadLine());
  11. int counter = 0;
  12. string prev = "";
  13.  
  14. for (int i = 0; i < n; i++)
  15. {
  16. string input = Console.ReadLine().Trim();
  17.  
  18. if (input == "(")
  19. {
  20. if (prev == input)
  21. {
  22. Console.WriteLine("UNBALANCED");
  23. return;
  24. }
  25. prev = input;
  26. counter++;
  27. }
  28.  
  29. if (input == ")")
  30. {
  31. if (counter == 0)
  32. {
  33. Console.WriteLine("UNBALANCED");
  34. return;
  35. }
  36. prev = "";
  37. counter--;
  38. }
  39. }
  40. if (counter == 0)
  41. {
  42. Console.WriteLine("BALANCED");
  43. }
  44. else
  45. {
  46. Console.WriteLine("UNBALANCED");
  47. }
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement