Advertisement
Guest User

08

a guest
Sep 22nd, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _08
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string inp = Console.ReadLine();
  14. Stack<char> str = new Stack<char>();
  15. for (int i = 0; i < inp.Length; i++)
  16. {
  17. char a = inp[i];
  18. if ((a == '(' || a == '[' || a == '{'))
  19. {
  20. str.Push(a);
  21. }
  22. else
  23. {
  24. if (str.Count > 0 && ((str.Peek() == '(' && a == ')') || (str.Peek() == '[' && a == ']') || (str.Peek() == '{' && a == '}')))
  25. {
  26. str.Pop();
  27. }
  28. else
  29. {
  30. Console.WriteLine("NO");
  31. Environment.Exit(0);
  32. }
  33. }
  34. }
  35. Console.WriteLine("YES");
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement