Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Numerics;
- namespace apps
- {
- class Program
- {
- static void Main()
- {
- // BALANCING
- int N = GetInt(); ;
- bool Unbalanced = false;
- string input = string.Empty;
- int Braket_Equality = 0;
- for(int i =0; i<N; i++)
- {
- input = Get();
- if (input == "(")
- {
- if (Braket_Equality > 1) { Unbalanced = true; } // mark as unbalanced if a bracket is not the right bracket
- Braket_Equality++;
- }
- if (input == ")")
- {
- if (Braket_Equality < -1) { Unbalanced = true; } // mark as unbalanced if a bracket is not the right bracket
- Braket_Equality--;
- }
- }
- if (Unbalanced) { Console.WriteLine("UNBALANCED"); }
- else
- {
- if (Braket_Equality == 0) { Console.WriteLine("BALANCED"); }
- else
- {
- Console.WriteLine("UNBALANCED");
- }
- }
- }
- //-----------------------------------------------------------------------------
- static int GetInt() { return int.Parse(Console.ReadLine()); }
- static string Get() { return Console.ReadLine(); }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement