Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2017
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. namespace _01.Type_Boundaries
  2. {
  3.     using System;
  4.    
  5.     public class TypeBoundaries
  6.     {
  7.         public static void Main()
  8.         {
  9.             byte n = byte.Parse(Console.ReadLine());
  10.             string result = "BALANCED";
  11.  
  12.             string brackets = string.Empty;
  13.          
  14.             for (int i = 0; i < n; i++)
  15.             {
  16.                 string str = Console.ReadLine();
  17.  
  18.                 if (str == "(" || str == ")")
  19.                 {
  20.                     brackets += str;
  21.                 }            
  22.             }
  23.  
  24.             if (brackets.Length % 2 == 1)
  25.             {
  26.                 result = "UNBALANCED";
  27.             }
  28.  
  29.             for (int j = 0; j < brackets.Length; j++)
  30.             {
  31.                 if (j % 2 == 0 && brackets[j] == ')')
  32.                 {
  33.                     result = "UNBALANCED";
  34.                     break;
  35.                 }
  36.                 if (j % 2 == 1 && brackets[j] == '(')
  37.                 {
  38.                     result = "UNBALANCED";
  39.                     break;
  40.                 }
  41.             }
  42.             Console.WriteLine(result);
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement