Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace BalancedBrackets
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine()),
- openBrackets = 0;
- string bracket;
- for (int i = 0; i < n; i++)
- {
- bracket = Console.ReadLine();
- if (bracket == ")") {
- openBrackets--;
- if (openBrackets < 0) {
- break;
- }
- } else if (bracket == "(") {
- openBrackets++;
- if (openBrackets > 1) {
- break;
- }
- }
- }
- if (openBrackets == 0)
- {
- Console.WriteLine("BALANCED");
- }
- else
- {
- Console.WriteLine("UNBALANCED");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement