Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _8._Balanced_Parentheses
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- Stack<string> stack = new Stack<string>();
- Queue<string> queue = new Queue<string>();
- for (int i = 0; i < input.Length; i++)
- {
- if (i < input.Length / 2)
- {
- stack.Push(input[i].ToString()); continue;
- }
- queue.Enqueue(input[i].ToString());
- }
- bool isParenthesis = false;
- while (queue.Any())
- {
- string currQ = queue.Dequeue();
- string currS = stack.Pop();
- if ((currS == "{" && currQ == "}")
- || (currS == "(" && currQ == ")")
- || (currS == "[" && currQ == "]"))
- { isParenthesis = true; continue; }
- break;
- }
- Console.WriteLine(isParenthesis ? "YES" : "NO");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement