Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace _08_Balanced_Parenthesis
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- foreach(var symbols in input)
- {
- if (symbols=='{'||symbols=='}' )
- {
- input = input.Replace(symbols, '1');
- }
- else if (symbols=='['||symbols==']' )
- {
- input = input.Replace(symbols, '2');
- }
- else if (symbols=='('||symbols==')' )
- {
- input = input.Replace(symbols, '3');
- }
- }
- var stack = new Stack<char>();
- for (int i = 0; i < input.Length; i++)
- {
- if (i<input.Length/2)
- {
- stack.Push(input[i]);
- }
- else
- {
- if (stack.Peek()==input[i])
- {
- stack.Pop();
- }
- else
- {
- Console.WriteLine("NO");
- return;
- }
- }
- }
- Console.WriteLine("YES");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement