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