Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _06BalancedBrackets
- {
- class Program
- {
- static void Main(string[] args)
- {
- var n = int.Parse(Console.ReadLine());
- int openingBracket = 0;
- int consecutiveOpeningBrackets = 0;
- for (int i = 1; i <= n; i++)
- {
- string text = Console.ReadLine();
- if (text == ")")
- {
- openingBracket--;
- if (openingBracket == -1)
- {
- consecutiveOpeningBrackets++;
- break;
- }
- }
- else if (text == "(")
- {
- openingBracket++;
- if (openingBracket == 2)
- {
- consecutiveOpeningBrackets++;
- break;
- }
- }
- }
- if (openingBracket == 0 && consecutiveOpeningBrackets == 0)
- {
- Console.WriteLine("BALANCED");
- }
- else
- {
- Console.WriteLine("UNBALANCED");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment