kmer

Untitled

Jan 31st, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. using System;
  2.  
  3. namespace BalancedBrackets
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int signLeft = 0;
  10. int signRight = 0;
  11. int sign = 0;
  12. bool n = true;
  13. int lines = int.Parse(Console.ReadLine());
  14. for (int i = 0; i < lines; i++)
  15. {
  16. string symbols = Console.ReadLine();
  17. if (symbols == "(")
  18. {
  19. signLeft += 1;
  20. }
  21. else if (symbols == ")")
  22. {
  23. signRight += 1;
  24. }
  25.  
  26. if (signLeft == 0 && signRight == 1)
  27. {
  28. n = false;
  29. sign = 1;
  30. }
  31. else if (signLeft == signRight && sign == 0)
  32. {
  33. signLeft = 0;
  34. signRight = 0;
  35. n = true;
  36. }
  37. else
  38. {
  39. n = false;
  40. }
  41.  
  42. }
  43.  
  44. if (n == true && sign == 0)
  45. {
  46. Console.WriteLine("BALANCED");
  47. }
  48. else
  49. {
  50. Console.WriteLine("UNBALANCED");
  51. }
  52.  
  53. }
  54. }
  55. }
Add Comment
Please, Sign In to add comment