Advertisement
martigpg3

Untitled

May 24th, 2025
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. using System.Numerics;
  2.  
  3. namespace _00.Demos
  4. {
  5.     //Martin
  6.     internal class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int lines = int.Parse(Console.ReadLine());
  11.             bool openedBraket = false;
  12.             bool isThereAProblamaticBraket = false;
  13.  
  14.             int openedBrakets = default;
  15.             for (int i = 0; i < lines; i++)
  16.             {
  17.                 string input = Console.ReadLine();
  18.                 for (int j = 0; j < input.Length; j++)
  19.                 {
  20.                     if (input[j] == '(' && !openedBraket)
  21.                     {
  22.                         openedBraket = true;
  23.                         openedBrakets++;
  24.                     }
  25.                     else if (input[j] == '(' && openedBraket)
  26.                     {
  27.                         isThereAProblamaticBraket = true;
  28.                     }
  29.                     if (input[j] == ')')
  30.                     {
  31.                         openedBraket = false;
  32.                         openedBrakets--;
  33.                     }
  34.                 }
  35.             }
  36.             if (isThereAProblamaticBraket)
  37.                 Console.WriteLine("UNBALANCED");
  38.             else
  39.             {
  40.                 if(!openedBraket && openedBrakets % 2 == 0 && openedBrakets >= 0)
  41.                     Console.WriteLine("BALANCED");
  42.                 else
  43.                     Console.WriteLine("UNBALANCED");
  44.             }
  45.         }
  46.     }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement