Advertisement
martigpg3

Untitled

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