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;
- using System.Threading.Tasks;
- namespace _08
- {
- class Program
- {
- static void Main(string[] args)
- {
- string inp = Console.ReadLine();
- Stack<char> str = new Stack<char>();
- for (int i = 0; i < inp.Length; i++)
- {
- char a = inp[i];
- if ((a == '(' || a == '[' || a == '{'))
- {
- str.Push(a);
- }
- else
- {
- if (str.Count > 0 && ((str.Peek() == '(' && a == ')') || (str.Peek() == '[' && a == ']') || (str.Peek() == '{' && a == '}')))
- {
- str.Pop();
- }
- else
- {
- Console.WriteLine("NO");
- Environment.Exit(0);
- }
- }
- }
- Console.WriteLine("YES");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement