Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _08._Balanced_Parenthesis
- {
- class Program
- {
- static void Main()
- {
- string input = Console.ReadLine();
- Stack<char> parenthesStack = new Stack<char>();
- foreach (var symbol in input)
- {
- if (parenthesStack.Any())
- {
- char check = parenthesStack.Peek();
- if (check == '{' && symbol == '}')
- {
- parenthesStack.Pop();
- continue;
- }
- else if (check == '[' && symbol == ']')
- {
- parenthesStack.Pop();
- continue;
- }
- else if (check == '(' && symbol == ')')
- {
- parenthesStack.Pop();
- continue;
- }
- }
- parenthesStack.Push(symbol);
- }
- Console.WriteLine(!parenthesStack.Any() ? "YES" : "NO");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement