nikolayneykov

Untitled

Feb 10th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. using System;
  2.  
  3. class BalancedBrackets
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         int n = int.Parse(Console.ReadLine());
  8.         int opening = 0;
  9.         int closing = 0;
  10.         for (int i = 0; i < n; i++)
  11.         {
  12.             string line = Console.ReadLine();
  13.             if (line == "(")
  14.             {
  15.                 opening++;
  16.             }
  17.             if (line == ")")
  18.             {
  19.                 closing++;
  20.             }
  21.             if (closing > opening)
  22.             {
  23.                 break;
  24.             }
  25.  
  26.         }
  27.         Console.WriteLine(opening == closing ? "BALANCED" : "UNBALANCED");
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment