Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int mas[100000];
  6.  
  7. int main()
  8. {
  9. FILE *fin, *fout;
  10. char st[10000], symb;
  11. int ind_high, i, quantity, flag;
  12. fin = fopen("brackets.in", "r");
  13. fout = fopen("brackets.out", "w");
  14. while (fgets(st, 10000, fin) != NULL)
  15. {
  16. ind_high = 0;
  17. flag = 0;
  18. quantity = 0;
  19. for (i = 0; i < strlen(st); i++)
  20. {
  21. symb = st[i];
  22. if (symb == '(')
  23. {
  24. mas[ind_high++] = 1;
  25. quantity++;
  26. }
  27. else if (symb == '[')
  28. {
  29. mas[ind_high++] = 2;
  30. quantity++;
  31. }
  32. else if (symb == ')')
  33. {
  34. if ((quantity > 0) && (mas[ind_high - 1] == 1))
  35. {
  36. mas[ind_high - 1] = 0;
  37. ind_high--;
  38. quantity--;
  39. }
  40. else
  41. {
  42. fprintf(fout, "NO\n");
  43. flag++;
  44. break;
  45. }
  46. }
  47. else if (symb == ']')
  48. {
  49. if ((quantity > 0) && (mas[ind_high - 1] == 2))
  50. {
  51. mas[ind_high - 1] = 0;
  52. ind_high--;
  53. quantity--;
  54. }
  55. else
  56. {
  57. fprintf(fout, "NO\n");
  58. flag++;
  59. break;
  60. }
  61. }
  62. }
  63. if (flag == 0)
  64. {
  65. if (quantity == 0)
  66. fprintf(fout, "YES\n");
  67. else
  68. fprintf(fout, "NO\n");
  69. }
  70. }
  71.  
  72. fclose(fin);
  73. fclose(fout);
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement