Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace P15_BalancedBrackets
- {
- class P15_BalancedBrackets
- {
- static void Main(string[] args)
- {
- byte n = byte.Parse(Console.ReadLine());
- byte open = 0; // OPENING BRACKETS
- byte close = 0; // CLOSING BRACKETS
- for(byte i = 1; i <= n; i++)
- {
- if(open == 1 && close == 1) // RESET
- {
- open--;
- close--;
- }
- string input = Console.ReadLine();
- switch(input)
- {
- case "(":
- open++;
- break;
- case ")":
- close++;
- break;
- }
- }
- if(open == 0 && close == 0)
- {
- Console.WriteLine("BALANCED");
- }
- else
- {
- Console.WriteLine("UNBALANCED");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement