Advertisement
Guest User

Untitled

a guest
May 4th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. static void Main(string[] args)
  2. {
  3. string[] arrBraces = Console.ReadLine().Split(' ');
  4. string[] result = new String[arrBraces.Length];
  5.  
  6. for (int i = 0; i < arrBraces.Length; i++) {
  7. Console.WriteLine(arrBraces[i]);
  8. int curly = 0, square = 0, round = 0;
  9.  
  10. foreach (char c in arrBraces[i]) {
  11. if (c == '{') {
  12. curly++;
  13. } else if (c == '[') {
  14. square++;
  15. } else if (c == '(') {
  16. round++;
  17. } else if (c == '}') {
  18. if (curly > 0) {
  19. curly--;
  20. } else {
  21. curly = -1;
  22. break;
  23. }
  24. } else if (c == ']') {
  25. if (square > 0) {
  26. square--;
  27. } else {
  28. square = -1;
  29. break;
  30. }
  31. } else if (c == ')') {
  32. if (round > 0) {
  33. round--;
  34. } else {
  35. round = -1;
  36. break;
  37. }
  38. }
  39. }
  40.  
  41. if (curly == 0 && square == 0 && round == 0) {
  42. result[i] = "YES";
  43. } else {
  44. result[i] = "NO";
  45. }
  46. }
  47.  
  48. foreach (string str in result) {
  49. Console.WriteLine (str);
  50. }
  51. Console.ReadKey();
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement