Advertisement
Guest User

Untitled

a guest
Apr 11th, 2020
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _08_Balanced_Parenthesis
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. string input = Console.ReadLine();
  13. foreach(var symbols in input)
  14. {
  15. if (symbols=='{'||symbols=='}' )
  16. {
  17. input = input.Replace(symbols, '1');
  18. }
  19. else if (symbols=='['||symbols==']' )
  20. {
  21. input = input.Replace(symbols, '2');
  22. }
  23. else if (symbols=='('||symbols==')' )
  24. {
  25. input = input.Replace(symbols, '3');
  26. }
  27.  
  28. }
  29. var stack = new Stack<char>();
  30.  
  31.  
  32. for (int i = 0; i < input.Length; i++)
  33. {
  34.  
  35. if (i<input.Length/2)
  36. {
  37.  
  38. stack.Push(input[i]);
  39. }
  40. else
  41. {
  42.  
  43. if (stack.Peek()==input[i])
  44. {
  45. stack.Pop();
  46. }
  47. else
  48. {
  49. Console.WriteLine("NO");
  50. return;
  51. }
  52.  
  53. }
  54. }
  55. Console.WriteLine("YES");
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement