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