Advertisement
Stan0033

Untitled

Jun 17th, 2021
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Numerics;
  4.  
  5. namespace apps
  6. {
  7.  
  8. class Program
  9. {
  10.  
  11.  
  12. static void Main()
  13. {
  14. // BALANCING
  15.  
  16. int N = GetInt(); ;
  17. bool Unbalanced = false;
  18.  
  19. string input = string.Empty;
  20.  
  21. int Braket_Equality = 0;
  22. for(int i =0; i<N; i++)
  23. {
  24. input = Get();
  25. if (input == "(")
  26. {
  27. if (Braket_Equality > 1) { Unbalanced = true; } // mark as unbalanced if a bracket is not the right bracket
  28. Braket_Equality++;
  29. }
  30. if (input == ")")
  31. {
  32. if (Braket_Equality < -1) { Unbalanced = true; } // mark as unbalanced if a bracket is not the right bracket
  33. Braket_Equality--;
  34. }
  35.  
  36. }
  37.  
  38. if (Unbalanced) { Console.WriteLine("UNBALANCED"); }
  39. else
  40. {
  41.  
  42. if (Braket_Equality == 0) { Console.WriteLine("BALANCED"); }
  43. else
  44. {
  45. Console.WriteLine("UNBALANCED");
  46. }
  47. }
  48.  
  49. }
  50. //-----------------------------------------------------------------------------
  51. static int GetInt() { return int.Parse(Console.ReadLine()); }
  52. static string Get() { return Console.ReadLine(); }
  53.  
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement