Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Balanced_Parentheses
- {
- using System;
- using System.Collections.Generic;
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- Queue<char> parenthesesQueue = new Queue<char>(input);
- Stack<char> parenthesesStack = new Stack<char>(input);
- int counter = 0;
- for (int i = 0; i < input.Length / 2; i++)
- {
- char symbolFromQueue = parenthesesQueue.Dequeue();
- char symbolFromStack = parenthesesStack.Pop();
- if (symbolFromQueue == '{' && symbolFromStack == '}')
- {
- counter++;
- }
- else if (symbolFromQueue == '(' && symbolFromStack == ')')
- {
- counter++;
- }
- else if (symbolFromQueue == '[' && symbolFromStack == ']')
- {
- counter++;
- }
- }
- if (counter == input.Length / 2)
- {
- Console.WriteLine("YES");
- }
- else
- {
- Console.WriteLine("NO");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement