Advertisement
Guest User

Balanced Brackets New

a guest
May 26th, 2019
2,338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Test
  5. {
  6.     class Program
  7.     {
  8.  
  9.         public static void Main()
  10.         {
  11.             long n = long.Parse(Console.ReadLine());
  12.             long openCount = 0;
  13.             long closeCount = 0;
  14.  
  15.             for (int i = 1; i <= n; i++)
  16.             {
  17.                 string input = Console.ReadLine();
  18.                 if (input=="(")
  19.                 {
  20.                     openCount++;
  21.                  
  22.                 }
  23.                 else if (input==")")
  24.                 {
  25.                     closeCount++;
  26.                    if (openCount - closeCount != 0)
  27.                         {
  28.                             Console.WriteLine("UNBALANCED");
  29.                             return;
  30.                         }
  31.                     }              
  32.             }
  33.             if (openCount==closeCount)
  34.             {
  35.                 Console.WriteLine("BALANCED");
  36.             }
  37.             else
  38.             {
  39.                 Console.WriteLine("UNBALANCED");
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement