DeeAG

06.BalancedBrackets

Apr 21st, 2021
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace _06.BalancedBrackets3
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.  
  13.             StringBuilder text = new StringBuilder();
  14.  
  15.             Regex regex = new Regex(@"^([^(\)]*\([^(\)]*\)[^(\)]*)*$");
  16.  
  17.             for (int i = 0; i < n; i++)
  18.             {
  19.                 string line = Console.ReadLine();
  20.                 text.Append(line);
  21.             }
  22.  
  23.             Match match = regex.Match(text.ToString());
  24.  
  25.             if (match.Success)
  26.             {
  27.                 Console.WriteLine("BALANCED");
  28.             }
  29.             else
  30.             {
  31.                 Console.WriteLine("UNBALANCED");
  32.             }
  33.         }
  34.     }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment