Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace Test
- {
- class Program
- {
- public static void Main()
- {
- long n = long.Parse(Console.ReadLine());
- long openCount = 0;
- long closeCount = 0;
- for (int i = 1; i <= n; i++)
- {
- string input = Console.ReadLine();
- if (input=="(")
- {
- openCount++;
- }
- else if (input==")")
- {
- closeCount++;
- if (openCount - closeCount != 0)
- {
- Console.WriteLine("UNBALANCED");
- return;
- }
- }
- }
- if (openCount==closeCount)
- {
- Console.WriteLine("BALANCED");
- }
- else
- {
- Console.WriteLine("UNBALANCED");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement