Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace BalancedParentheses
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- Stack<char> stackParentheses = new Stack<char>();
- bool isSuccess = true;
- for (int i = 0; i < input.Length; i++)
- {
- if (input[i] == '{' || input[i] == '[' || input[i] == '(')
- {
- stackParentheses.Push(input[i]);
- }
- else
- {
- if (input[i] == '}' && stackParentheses.Pop() == '{' || input[i] == ']' && stackParentheses.Pop() == '[' || input[i] == ')' && stackParentheses.Pop() == '(')
- {
- isSuccess = true;
- }
- else
- {
- isSuccess = false;
- break;
- }
- }
- }
- if (isSuccess == true)
- {
- Console.WriteLine("YES");
- }
- else
- {
- Console.WriteLine("NO");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement