Advertisement
Terziyski

Problem 15. * Balanced Brackets

Jun 6th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Problem_15.Star__Balanced_Brackets
  8. {
  9.     class BalancedBrackets
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int input = int.Parse(Console.ReadLine());
  14.  
  15.  
  16.             int countOpenBracket = 0;
  17.             int countClosingBRacket = 0;
  18.  
  19.  
  20.             for (int i = 1; i <= input; i++)
  21.             {
  22.                 string text = Console.ReadLine();
  23.  
  24.                 foreach (char openBracket in text)
  25.                 {
  26.                     if (openBracket == '(')
  27.                     {
  28.                         countOpenBracket++;
  29.                     }
  30.                     if (openBracket == ')')
  31.                     {
  32.                         countClosingBRacket++;
  33.                     }
  34.  
  35.                 }
  36.             }
  37.  
  38.             if (countOpenBracket == countClosingBRacket)
  39.             {
  40.                 Console.WriteLine("BALANCED");
  41.             }
  42.             else
  43.             {
  44.                 Console.WriteLine("UNBALANCED");
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement