Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace balancedBreckets
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- int numberOfLines = int.Parse(Console.ReadLine());
- List < string > listOfOpenedBrackets= new List<string>();
- List<string> listOfClosedBrackets= new List<string>();
- for (int i = 0; i < numberOfLines; i++)
- {
- string input = Console.ReadLine();
- if (input == ")"&& listOfOpenedBrackets.Count==0)
- {
- Console.WriteLine("UNBALANCED");
- return;
- }
- else if (input == "(")
- {
- listOfOpenedBrackets.Add(input);
- if (listOfOpenedBrackets.Count == 2)
- {
- Console.WriteLine("UNBALANCED");
- return;
- }
- }
- else if (input == ")")
- {
- listOfClosedBrackets.Add(input);
- if (listOfClosedBrackets.Count == 2)
- {
- Console.WriteLine("UNBALANCED");
- return;
- }
- }
- if (listOfOpenedBrackets.Count==1 && listOfClosedBrackets.Count==1)
- {
- listOfOpenedBrackets.Clear();
- listOfClosedBrackets.Clear();
- }
- }
- if (listOfOpenedBrackets.Count==listOfClosedBrackets.Count)
- {
- Console.WriteLine("BALANCED");
- }
- else
- {
- Console.WriteLine("UNBALANCED");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement