Advertisement
Guest User

15.Balanced Brackets

a guest
Feb 9th, 2018
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. using System;
  2.  
  3. namespace P15_BalancedBrackets
  4. {
  5.     class P15_BalancedBrackets
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             byte n = byte.Parse(Console.ReadLine());
  10.             byte open = 0;      // OPENING BRACKETS
  11.             byte close = 0;     // CLOSING BRACKETS
  12.  
  13.             for(byte i = 1; i <= n; i++)
  14.             {
  15.                 if(open == 1 && close == 1) // RESET
  16.                 {
  17.                     open--;
  18.                     close--;
  19.                 }
  20.  
  21.                 string input = Console.ReadLine();
  22.                 switch(input)
  23.                 {
  24.                     case "(":
  25.                         open++;
  26.                         break;
  27.                     case ")":
  28.                         close++;
  29.                         break;
  30.                 }
  31.             }
  32.             if(open == 0 && close == 0)
  33.             {
  34.                 Console.WriteLine("BALANCED");
  35.             }
  36.             else
  37.             {
  38.                 Console.WriteLine("UNBALANCED");
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement